Skip to content

Instantly share code, notes, and snippets.

@aguilarsoto
Created April 21, 2012 00:02
Show Gist options
  • Select an option

  • Save aguilarsoto/2432748 to your computer and use it in GitHub Desktop.

Select an option

Save aguilarsoto/2432748 to your computer and use it in GitHub Desktop.
pascal triangle out to out.txt and length received by console
def pascal(n)
file = File.open("out.txt", "w")
p=[1]
while(p.length<n)
file.write(p.join(" ")+"\n")
p=Array.new(p.length+1) do |i|
a=i<p.length ? p[i] : 0
b=i>0 ? p[i-1] : 0
a+b
end
end
end
pascal(ARGV.first.to_i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment