Skip to content

Instantly share code, notes, and snippets.

@IrakliJani
Last active December 10, 2015 18:29
Show Gist options
  • Save IrakliJani/4474762 to your computer and use it in GitHub Desktop.
Save IrakliJani/4474762 to your computer and use it in GitHub Desktop.
Fibonacci number in ruby using ruby's default hash value
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