Last active
August 29, 2015 14:12
-
-
Save nekoTheShadow/c8861aa6d8be466b86c2 to your computer and use it in GitHub Desktop.
This file contains 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
# Here your code ! | |
module FibSupport | |
def idx2fib(idx, a=1, b=0) | |
idx == 1 ? a : idx2fib(idx-1,a+b,a) | |
end | |
end | |
class Fib | |
include FibSupport | |
def initialize(n=nil) | |
@n = n | |
@range = (@n == nil) ? (1..Float::INFINITY) : (1..@n) | |
end | |
def all | |
@n != nil ? @range.map{|idx| idx2fib(idx)} : nil | |
end | |
def at(i) | |
@range.include?(i) ? idx2fib(i) : nil | |
end | |
end | |
fib = Fib.new(10) | |
p fib.all | |
p fib.at(3) | |
p fib.at(11) | |
fib2 = Fib.new | |
p fib2.all | |
p fib2.at(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
paizaIOとの連携テスト。あとコメント投稿もテスト。