Created
December 3, 2011 16:05
-
-
Save ngm/1427458 to your computer and use it in GitHub Desktop.
Seven Languages in Seven Weeks - Io - Day 2 - Fibonacci
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
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) |
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
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