Created
August 12, 2012 14:37
-
-
Save cloverrose/3332119 to your computer and use it in GitHub Desktop.
Seven language "Io" p61
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
// Seven language "Io" day2 Q1 | |
// fib | |
fib_recur := method(if((call sender doMessage(call message argAt(0))) == 1, 1, | |
if((call sender doMessage(call message argAt(0))) == 2, 1, | |
fib_recur( (call sender doMessage(call message argAt(0))) -1) + | |
fib_recur( (call sender doMessage(call message argAt(0))) -2)))) | |
(fib_recur(1) == 1 and | |
fib_recur(2) == 1 and | |
fib_recur(3) == 2 and | |
fib_recur(4) == 3 and | |
fib_recur(5) == 5 and | |
fib_recur(6) == 8 and | |
fib_recur(7) == 13 and | |
fib_recur(8) == 21) println | |
fib_loop := method( | |
arg := (call sender doMessage(call message argAt(0))); | |
x := 1; | |
//x println; | |
if(arg == 1, x, | |
y := 1; | |
//y println; | |
if(arg == 2, y, | |
for(i, 3, arg, 1, z := x; x := y; y := z + y; /*y println*/); | |
y))) | |
(fib_loop(1) == 1 and | |
fib_loop(2) == 1 and | |
fib_loop(3) == 2 and | |
fib_loop(4) == 3 and | |
fib_loop(5) == 5 and | |
fib_loop(6) == 8 and | |
fib_loop(7) == 13 and | |
fib_loop(8) == 21) println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment