Jump to content

Pascal's triangle: Difference between revisions

(Added RapidQ, added note on BASIC)
Line 255:
*Main> take 6 pascal
[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1]]
</pre>
 
A shorter approach, plagiarized from [http://www.haskell.org/haskellwiki/Blow_your_mind]
<pre>
-- generate next row from current row
nextRow row = zipWith (+) ([0] ++ row) (row ++ [0])
 
-- returns the first n rows
pascal = iterate nextRow [1]
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.