Created
August 11, 2012 15:14
-
-
Save dproject21/3325194 to your computer and use it in GitHub Desktop.
フィボナッチ数かどうかを検証する。
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
require './fib_map' | |
@fib_map = FibMap.new(100) | |
(0..100).each {|item| | |
if @fib_map.fibonacci?(item) then | |
p 'HENTAI!' | |
else | |
p item | |
end | |
} |
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
class FibMap | |
@@fibonacci = [] | |
def initialize(num) | |
@a = 0 | |
@b = 0 | |
0.upto(num) do |item| | |
if item == 0 then | |
@@fibonacci << item | |
@a = 0 | |
@b = 1 | |
elsif item == @a + @b then | |
@@fibonacci << item | |
@a = @b | |
@b = item | |
end | |
end | |
end | |
def print_fibonacci | |
@@fibonacci.each do |item| | |
p item | |
end | |
end | |
def fibonacci?(num) | |
@@fibonacci.index(num) != nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment