Skip to content

Instantly share code, notes, and snippets.

@kiennt
Forked from anonymous/fibo_dictionary.rb
Created February 25, 2013 17:00
Show Gist options
  • Save kiennt/5031301 to your computer and use it in GitHub Desktop.
Save kiennt/5031301 to your computer and use it in GitHub Desktop.
class FiboUsingDictionary
include Singleton
def initialize
@fib = { 0 => 1, 1 => 1 }
end
def [](n)
return @fib[n] if @fib.include? n
@fib[n] = self[n -1] + self[n - 2]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment