Last active
December 10, 2015 18:29
-
-
Save IrakliJani/4474762 to your computer and use it in GitHub Desktop.
Fibonacci number in ruby using ruby's default hash value
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
fib = Hash.new do |hash, key| | |
if [0, 1].include? key | |
hash[key] = key | |
else | |
hash[key] = hash[key - 1] + hash[key - 2] | |
end | |
end | |
fib[123] | |
=> 22698374052006863956975682 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment