Anonymous user
Pascal's triangle: Difference between revisions
Updated second D version
(Updated second D version) |
|||
Line 495:
<lang d>import std.stdio, std.algorithm, std.range;
auto pascal(
return [1].recurrence!q{ zip(a[n - 1] ~ 0, 0 ~ a[n - 1])
.map!q{a[0] + a[1]}
}
void main() {
}</lang>
{{out}}
<pre>[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]</pre>
===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).
|