Pascal's triangle: Difference between revisions

added FunL
(added FunL)
Line 1,042:
 
END SUBROUTINE Print_Triangle</lang>
 
=={{header|FunL}}==
=== Summing from Previous Rows ===
{{trans|Scala}}
<lang funl>import lists.zip
 
def
pascal( 1 ) = [1]
pascal( n ) = [1] + map( ((a, b)) -> a + b, zip(pascal(n-1), pascal(n-1).tail()) ) + [1]</lang>
 
=== Combinations ===
{{trans|Haskell}}
<lang funl>import integers.choose
 
def pascal( n ) = [choose( n - 1, k ) | k <- 0..n-1]</lang>
 
=== Pascal's Triangle ===
<lang funl>def triangle( height ) =
width = max( map(a -> a.toString().length(), pascal(height)) )
 
if 2|width
width++
 
for n <- 1..height
print( ' '*((width + 1)\2)*(height - n) )
println( map(a -> format('%' + width + 'd ', a), pascal(n)).mkString() )
 
triangle( 10 )</lang>
 
<pre>
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
</pre>
 
=={{header|GAP}}==
Anonymous user