Created
April 11, 2018 07:47
-
-
Save muirandy/128d6d5de34dd22c3595f45843aea5c0 to your computer and use it in GitHub Desktop.
Fibonacci sequence in Io language
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
Number fib := method( | |
values := list(1,1) | |
if (self == 1) then( | |
self println | |
) else( | |
if (self == 2) then (1 println) else( | |
for(i, 3, self, | |
self fibAtIndex(values) | |
) | |
values last println | |
) | |
) | |
) | |
Number fibAtIndex := method(values, | |
newResult := values at(-1) + values at(-2) | |
values append(newResult) | |
values | |
) | |
1 fib | |
2 fib | |
3 fib | |
4 fib | |
45 fib | |
1146 fib |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment