Last active
June 21, 2018 15:38
-
-
Save kirqe/f053fe1274261f7301415bf2e0f06561 to your computer and use it in GitHub Desktop.
ruby fibonacci sequence?
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 fib_seq(n) | |
one, two, index, sequence = 0, 1, 0, [] | |
while index < n | |
one, two = two, (one + two) | |
sequence << two | |
index = index + 1 | |
end | |
sequence | |
end | |
p fib_seq(10) #=> [1, 2, 3, 5, 8, 13, 21, 34, 55, 89] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment