Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. def fibonacci(index)
  2. arr = [0, 1]
  3. while arr.length < index
  4. if arr.length > 3 # I'll be damned if arr[3] is going to spoil my quick code >:O
  5. arr[3] = 2
  6. end
  7. num1 = arr.index(arr.last)
  8. num2 = arr.index(arr.last)-1
  9. next_value = arr[num1]+arr[num2]
  10. arr << next_value
  11. end
  12. p arr[index-1]
  13. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement