Pascal's triangle: Difference between revisions

Line 314:
auto pascal(int n) {
auto p = [[1]];
foreach (_; 01 .. n)
p ~= array(map!q{a[0] + a[1]}(zip(p[$-1] ~ 0, 0 ~ p[$-1])));
return p;
Line 323:
}</lang>
Output:
<pre>[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1]]</pre>
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.format : fmx = format;
Anonymous user