Jump to content

Pascal's triangle: Difference between revisions

Add Factor
(C)
(Add Factor)
Line 258:
foreach(i ; [16]) writef(sierpinski(i)) ;
}</lang>
 
=={{header|Factor}}==
 
This implementation works by summing the previous line content. Result for n < 1 is the same as for n == 1.
 
<lang factor>
USING: grouping kernel math sequences ;
 
: (pascal) ( seq -- newseq )
dup peek 0 prefix 0 suffix 2 <clumps> [ sum ] map suffix ;
 
: pascal ( n -- seq )
1 - { { 1 } } swap [ (pascal) ] times ;
</lang>
 
It works as:
 
<lang factor>
5 pascal .
{ { 1 } { 1 1 } { 1 2 1 } { 1 3 3 1 } { 1 4 6 4 1 } }
</lang>
 
=={{header|Forth}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.