Pascal's triangle: Difference between revisions
Content deleted Content added
Line 324:
=={{header|Groovy}}==
=== Recursive
In the spirit of the Haskell "think in whole lists" solution here is a list-driven, minimalist solution:
<lang groovy>pascal = { n -> (n <= 1) ? [1] : GroovyCollections.transpose([[0] + pascal(n - 1), pascal(n - 1) + [0]]).collect { it.sum() } }</lang>
Line 330:
Program for unformatted output:
<lang groovy>
(1..count).each { n ->
printf ("%2.0f:", n as float); (0..(count-n)).each { print " " }; pascal(n).each{ printf("%6.0f ", it as float) }; println ""
}</lang>
Output:
<pre> 1: 1
2: 1 1
3: 1 2 1
4: 1 3 3 1
5: 1 4 6 4 1
6: 1 5 10 10 5 1
7: 1 6 15 20 15 6 1
8:
9:
10:
11:
12:
13:
14:
15:
=={{header|Haskell}}==
|