Skip to content

Instantly share code, notes, and snippets.

@kyuden
Created July 9, 2013 16:54
Show Gist options
  • Save kyuden/5959081 to your computer and use it in GitHub Desktop.
Save kyuden/5959081 to your computer and use it in GitHub Desktop.
Fibona
module Fibona
@@memo = [0 , 1];
def self.[](n)
#既にメモされている最大の値から計算開始
#求めたい値が既に計算済みならこのループは実行されない
@@memo.size.upto(n){|i| @@memo[i] = @@memo[i - 1] + @@memo[i - 2]}
@@memo[n]
end
end
5000.times{|n| Fibona[n]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment