Pascal's triangle: Difference between revisions

No edit summary
Line 2,735:
</pre>
 
Another solution using matrix exponentiation.
 
<lang Julia>
iround(x) = round(Int64, x)
 
triangle(n) = iround.(expm(diagm(1:n, -1)))
 
function pascal(n)
println.(join.([filter(!iszero, triangle(n)[i,:]) for i in 1:(n+1)], " "))
return
end
</lang>
 
{{Out}}
 
<pre>
pascal(5)
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
</pre>
 
=={{header|K}}==