Skip to content

Instantly share code, notes, and snippets.

@mbeltagy
Created November 9, 2019 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbeltagy/34d3b3c29dc62a9802aa9d4373518fb2 to your computer and use it in GitHub Desktop.
Save mbeltagy/34d3b3c29dc62a9802aa9d4373518fb2 to your computer and use it in GitHub Desktop.
Pascal Triangle calculation
"Pascal triangle"
function pascal(n)
(n<=0) && error("Pascal trinalge can not have zero or negative rows")
r=Vector{Int}(undef,n)
pr=Vector{Int}(undef,n)
pr[1]=r[1]=1
println(@view pr[1])
for i=2:n
r[1]=r[i]=1
for j=2:i-1
r[j]=pr[j-1]+pr[j]
end
println(join(view(r,1:i), " "))
r,pr=pr,r
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment