Created
April 21, 2012 00:02
-
-
Save aguilarsoto/2432748 to your computer and use it in GitHub Desktop.
pascal triangle out to out.txt and length received by console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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