Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fibonacci(index)
- arr = [0, 1]
- while arr.length < index
- if arr.length > 3 # I'll be damned if arr[3] is going to spoil my quick code >:O
- arr[3] = 2
- end
- num1 = arr.index(arr.last)
- num2 = arr.index(arr.last)-1
- next_value = arr[num1]+arr[num2]
- arr << next_value
- end
- p arr[index-1]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement