-
-
Save tessafallon/7944706 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_relative "fibonacci_solution" | |
describe "fibo finder" do | |
it "it should return the nth number of the fibonacci sequence" do | |
fibo_finder(0).should eq(0) | |
end | |
it "it should return the nth number of the fibonacci sequence" do | |
fibo_finder(1).should eq(1) | |
end | |
it "it should return the nth number of the fibonacci sequence" do | |
fibo_finder(4).should eq(3) | |
end | |
it "it should return the nth number of the fibonacci sequence" do | |
fibo_finder(7).should eq(13) | |
end | |
it "it should return the nth number of the fibonacci sequence" do | |
fibo_finder(10).should eq(55) | |
end | |
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
# prereqs: arrays, methods, conditional logic | |
# create a method that returns the nth number of the fibonacci sequence | |
# fib sequence = 0,1,1,2,3,5,8,13 etc, assume the 1st element is 0 (the first number), the 2nd element is 1, the third element is 1 | |
def fibo_finder(n) | |
# code goes here | |
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
def fibo_finder(n) | |
if n == 0 | |
return 0 | |
elsif n == 1 | |
return 1 | |
else | |
sequence = [0,1] | |
(n - 1).times do | |
sequence << sequence[-1] + sequence[-2] | |
end | |
end | |
return sequence.last | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment