Skip to content

Instantly share code, notes, and snippets.

@fukaoi
Created January 31, 2014 08:37
Show Gist options
  • Save fukaoi/8728494 to your computer and use it in GitHub Desktop.
Save fukaoi/8728494 to your computer and use it in GitHub Desktop.
Fibonacci ruby
#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