Created
January 31, 2014 08:37
-
-
Save fukaoi/8728494 to your computer and use it in GitHub Desktop.
Fibonacci ruby
This file contains 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
#recurcive pattern, to sum | |
one = 1; two = 1 | |
10.times do |i| | |
if i <= 1; calc = one | |
else | |
calc = one + two | |
one, two = two, calc | |
end | |
p calc | |
end | |
puts '#############################' | |
#recurcive pattern, to sum | |
def fibonacci(cnt) | |
if cnt <= 2 | |
return 1 | |
else | |
return fibonacci(cnt - 2) + fibonacci(cnt - 1) | |
end | |
end | |
p fibonacci(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment