6 kyu

Pascal's Triangle

1,605 of 11,680boatmeme

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]
Arrays
Mathematics
Algorithms

Stats:

CreatedSep 4, 2013
PublishedSep 4, 2013
Warriors Trained28192
Total Skips6495
Total Code Submissions73792
Total Times Completed11680
JavaScript Completions5574
Ruby Completions1380
CoffeeScript Completions196
C# Completions1390
Haskell Completions494
PHP Completions623
Python Completions1605
Crystal Completions14
Java Completions327
Rust Completions169
C++ Completions344
C Completions85
COBOL Completions4
Total Stars640
% of votes with a positive feedback rating90% of 1502
Total "Very Satisfied" Votes1250
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