Created
July 9, 2013 16:54
-
-
Save kyuden/5959081 to your computer and use it in GitHub Desktop.
Fibona
This file contains hidden or 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
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