Skip to content

Instantly share code, notes, and snippets.

@ngm
Created December 3, 2011 16:05
Show Gist options
  • Save ngm/1427458 to your computer and use it in GitHub Desktop.
Save ngm/1427458 to your computer and use it in GitHub Desktop.
Seven Languages in Seven Weeks - Io - Day 2 - Fibonacci
fibonacci_loopy := method(n,
fib_list := List clone
for(i, 0, n-1,
if (i == 0 or i == 1,
fib_list append(1),
fib_list append(fib_list at(i-2) + fib_list at(i-1))
)
)
fib_list at(fib_list size-1)
)
Range 1 to(10) foreach(n, (fibonacci_loopy(n).." ") print)
fibonacci_recursive := method(n,
if (n == 1, return 1)
if (n == 2, return 1)
fibonacci_recursive(n-2) + fibonacci_recursive(n-1)
)
Range 1 to(10) foreach(n, (fibonacci_recursive(n).." ") print)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment