-
-
Save efecarranza/44c68b621374fc1683ff to your computer and use it in GitHub Desktop.
Interque Question - Fibonacci Code
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
def fibs(n) | |
first_fib = 1 | |
second_fib = 1 | |
result = [first_fib, second_fib] | |
if n < 1 | |
return "Please enter a valid number, it has to be greater than or equal to 1." | |
end | |
while second_fib < n | |
temp_fib = second_fib | |
second_fib += first_fib | |
first_fib = temp_fib | |
result.push(second_fib) | |
end | |
return result | |
end | |
def test_fib | |
test_number = 3 | |
known_result = [1, 1, 2, 3] | |
fibs(test_number) == known_result | |
end | |
puts test_fib | |
puts "*****************" | |
p fibs(0) | |
p fibs(75025) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment