Skip to content

Instantly share code, notes, and snippets.

@wheresalice
Created May 3, 2011 12:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheresalice/953213 to your computer and use it in GitHub Desktop.
Save wheresalice/953213 to your computer and use it in GitHub Desktop.
Fibonacci series in Io language
#!/usr/bin/env io
fib := method(
a := 0
b := 1
for(i, 1, doMessage(call message argAt(0)) - 1, c := a + b; a := b; b := c)
)
fib(10) println
@kennym
Copy link

kennym commented Jul 30, 2011

This is very clever, if you compare it with the other algorithm here: http://www.bennadel.com/blog/2066-Seven-Languages-In-Seven-Weeks-Io-Day-2.htm

@MrRabbit0o0
Copy link

Thank you for your answer. It helps me a lot.:)

@zobnin
Copy link

zobnin commented Feb 26, 2024

More readable version:

fib := method(arg, 
    a := 0
    b := 1
    for(i, 1, arg - 1, 
        tmp := a + b
        a := b
        b := tmp
    )
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment