6 kyu

Pascal's Triangle

5,575 of 11,685boatmeme

Description:

In mathematics, Pascal's triangle is a triangular array of the binomial coefficients expressed with formula

(nk)=n!k!(nk)!\lparen {n \atop k} \rparen = \frac {n!} {k!(n-k)!}

where n denotes a row of the triangle, and k is a position of a term in the row.

Pascal's Triangle

You can read Wikipedia article on Pascal's Triangle for more information.

Task

Write a function that, given a depth n, returns n top rows of Pascal's Triangle flattened into a one-dimensional list/array.

Example:

n = 1: [1]
n = 2: [1,  1, 1]
n = 4: [1,  1, 1,  1, 2, 1,  1, 3, 3, 1]

Note

Beware of overflow. Requested terms of a triangle are guaranteed to fit into the returned type, but depending on selected method of calculations, intermediate values can be larger.

Arrays
Mathematics
Algorithms

Stats:

CreatedSep 4, 2013
PublishedSep 4, 2013
Warriors Trained28237
Total Skips6495
Total Code Submissions73802
Total Times Completed11685
JavaScript Completions5575
Ruby Completions1381
CoffeeScript Completions196
C# Completions1390
Haskell Completions494
PHP Completions623
Python Completions1608
Crystal Completions14
Java Completions327
Rust Completions170
C++ Completions345
C Completions85
COBOL Completions4
Total Stars640
% of votes with a positive feedback rating90% of 1503
Total "Very Satisfied" Votes1251
Total "Somewhat Satisfied" Votes218
Total "Not Satisfied" Votes34
Ad
Contributors
  • boatmeme Avatar
  • jhoffner Avatar
  • manuc66 Avatar
  • jerub Avatar
  • GiacomoSorbi Avatar
  • pablo.varela Avatar
  • user4190256 Avatar
  • anter69 Avatar
  • Frenetiq Avatar
  • donaldsebleung Avatar
  • Chrono79 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • Blind4Basics Avatar
  • Firefly2002 Avatar
  • Voile Avatar
  • FArekkusu Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • tonylicoding Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • dfhwze Avatar
  • saudiGuy Avatar
Ad