Pascal's triangle: Difference between revisions

Line 326:
=== Recursive ===
In the spirit of the Haskell "think in whole lists" solution here is a list-driven, minimalist solution:
<lang groovy>def pascal = { n -> (n <= 1) ? [1] : GroovyCollections.transpose([[0] + pascal(n - 1), pascal(n - 1) + [0]]).collect { it.sum() } }</lang>
However, this solution is horribly inefficient (O(''n''**2)). It slowly grinds to a halt on a reasonably powerful PC after about line 25 of the triangle.
 
Anonymous user