Skip to content

Instantly share code, notes, and snippets.

@efecarranza
Created April 17, 2015 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efecarranza/44c68b621374fc1683ff to your computer and use it in GitHub Desktop.
Save efecarranza/44c68b621374fc1683ff to your computer and use it in GitHub Desktop.
Interque Question - Fibonacci Code
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