Skip to content

Instantly share code, notes, and snippets.

@kirqe
Last active June 21, 2018 15:38
Show Gist options
  • Save kirqe/f053fe1274261f7301415bf2e0f06561 to your computer and use it in GitHub Desktop.
Save kirqe/f053fe1274261f7301415bf2e0f06561 to your computer and use it in GitHub Desktop.
ruby fibonacci sequence?
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