Pascal's triangle: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: add output) |
({{Out}}) |
||
Line 1: | 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]]. |
{{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 1 |
1 1 |
||
Line 112: | Line 113: | ||
row := row[AT 1] + row[AT 2] |
row := row[AT 1] + row[AT 2] |
||
OD</lang> |
OD</lang> |
||
{{Out}}<pre> |
|||
Output: |
|||
1 |
1 |
||
1 1 |
1 1 |
||
Line 122: | Line 123: | ||
1 7 21 35 35 21 7 1 |
1 7 21 35 35 21 7 1 |
||
1 8 28 56 70 56 28 8 1 |
1 8 28 56 70 56 28 8 1 |
||
</pre> |
|||
=={{header|APL}}== |
=={{header|APL}}== |
||
Line 249: | Line 251: | ||
PRINT |
PRINT |
||
NEXT row%</lang> |
NEXT row%</lang> |
||
{{Out}} |
|||
Output: |
|||
<pre> 1 |
<pre> 1 |
||
1 1 |
1 1 |
||
Line 280: | Line 282: | ||
& |
& |
||
)</lang> |
)</lang> |
||
{{Out}} |
|||
Output: |
|||
<pre>Number of rows? |
<pre>Number of rows? |
||
7 |
7 |
||
Line 589: | Line 591: | ||
</lang> |
</lang> |
||
{{Out}} |
|||
output |
|||
<pre> |
<pre> |
||
> coffee pascal.coffee |
> coffee pascal.coffee |
||
Line 660: | Line 662: | ||
===Alternative Version=== |
===Alternative Version=== |
||
There is similarity between Pascal's triangle and [[Sierpinski triangle]]. |
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; |
<lang d>import std.stdio, std.string, std.array, std.format; |
||
Line 753: | Line 757: | ||
Pascal(9);</lang> |
Pascal(9);</lang> |
||
{{Out}}<pre> 1 |
|||
1 1 |
1 1 |
||
1 2 1 |
1 2 1 |
||
Line 915: | Line 919: | ||
</lang> |
</lang> |
||
{{Out}} |
|||
Output: |
|||
<pre> |
|||
Eshell V5.5.5 (abort with ^G) |
Eshell V5.5.5 (abort with ^G) |
||
1> pascal:pascal(5). |
1> pascal:pascal(5). |
||
[[1,4,6,4,1],[1,3,3,1],[1,2,1],[1,1],[1]] |
[[1,4,6,4,1],[1,3,3,1],[1,2,1],[1,1],[1]] |
||
</pre> |
|||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |
||
Line 934: | Line 939: | ||
end for</lang> |
end for</lang> |
||
{{Out}}<pre> |
|||
Output: |
|||
{1} |
{1} |
||
{1,1} |
{1,1} |
||
Line 945: | Line 950: | ||
{1,8,28,56,70,56,28,8,1} |
{1,8,28,56,70,56,28,8,1} |
||
{1,9,36,84,126,126,84,36,9,1} |
{1,9,36,84,126,126,84,36,9,1} |
||
</pre> |
|||
=={{header|F Sharp|F#}}== |
=={{header|F Sharp|F#}}== |