Last active
August 29, 2015 14:21
-
-
Save yowasou/457f6feec4f8f62d9727 to your computer and use it in GitHub Desktop.
Hamamatsu.rb 52 フィボナッチ数列
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 fib(x) | |
#ゼロ始まり | |
a = 0 #ふたつ前の結果 | |
b = 1 #ひとつ前の結果 | |
c = 1 #現在の結果 | |
for i in 0..x-1 | |
c = a + b | |
a = b | |
b = c | |
end | |
return c | |
end | |
puts fib(0) | |
puts fib(1) | |
puts fib(2) | |
puts fib(3) | |
puts fib(4) | |
puts fib(5) | |
puts fib(6) | |
puts fib(7) | |
puts fib(8) | |
puts fib(9) | |
puts fib(10) | |
puts fib(100) | |
puts fib(1000) | |
puts fib(10000) | |
puts fib(100000) | |
#puts fib(1000000) おそい |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment