Skip to content

Instantly share code, notes, and snippets.

@muirandy
Created April 11, 2018 07:47
Show Gist options
  • Save muirandy/128d6d5de34dd22c3595f45843aea5c0 to your computer and use it in GitHub Desktop.
Save muirandy/128d6d5de34dd22c3595f45843aea5c0 to your computer and use it in GitHub Desktop.
Fibonacci sequence in Io language
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