Anonymous user
Pascal's triangle: Difference between revisions
{{Out}}
(→{{header|Ruby}}: add output) |
({{Out}}) |
||
Line 1:
{{task|Arithmetic operations}}[[wp:Pascal's triangle|Pascal's triangle]] is an arithmetic and geometric figure first imagined by [[wp:Blaise Pascal|Blaise Pascal]].
Its first few rows look like this:
1
1 1
Line 112 ⟶ 113:
row := row[AT 1] + row[AT 2]
OD</lang>
{{Out}}<pre>
1
1 1
Line 122 ⟶ 123:
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
</pre>
=={{header|APL}}==
Line 249 ⟶ 251:
PRINT
NEXT row%</lang>
{{Out}}
<pre> 1
1 1
Line 280 ⟶ 282:
&
)</lang>
{{Out}}
<pre>Number of rows?
7
Line 589 ⟶ 591:
</lang>
{{Out}}
<pre>
> coffee pascal.coffee
Line 660 ⟶ 662:
===Alternative Version===
There is similarity between Pascal's triangle and [[Sierpinski triangle]].
Their difference are the initial line and the operation that act on the line element to produce next line.
The following is a generic pascal's triangle implementation for positive number of lines output (n).
<lang d>import std.stdio, std.string, std.array, std.format;
Line 753 ⟶ 757:
Pascal(9);</lang>
1 1
1 2 1
Line 915 ⟶ 919:
</lang>
{{Out}}
<pre>
Eshell V5.5.5 (abort with ^G)
1> pascal:pascal(5).
[[1,4,6,4,1],[1,3,3,1],[1,2,1],[1,1],[1]]
</pre>
=={{header|Euphoria}}==
Line 934 ⟶ 939:
end for</lang>
{{Out}}<pre>
{1}
{1,1}
Line 945 ⟶ 950:
{1,8,28,56,70,56,28,8,1}
{1,9,36,84,126,126,84,36,9,1}
</pre>
=={{header|F Sharp|F#}}==
|