Pascal's triangle: Difference between revisions
Content added Content deleted
(C) |
(Add Factor) |
||
Line 258: | Line 258: | ||
foreach(i ; [16]) writef(sierpinski(i)) ; |
foreach(i ; [16]) writef(sierpinski(i)) ; |
||
}</lang> |
}</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}}== |
=={{header|Forth}}== |