From 8ae4691e677414843cf3a84d4327d303fe3e2f41 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Mon, 2 Apr 2012 20:48:33 +0200 Subject: [Io] Día 2 --- io/fib.io | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 io/fib.io (limited to 'io/fib.io') diff --git a/io/fib.io b/io/fib.io new file mode 100644 index 0000000..46a6d54 --- /dev/null +++ b/io/fib.io @@ -0,0 +1,23 @@ +fib_rec := method(pos, + if (pos == 1 or pos == 2) then ( + return 1 + ) else ( + return fib_rec(pos-1) + fib_rec(pos-2) + ) +) + +fib_loop := method(pos, + fst := 0 + snd := 1 + result := nil + (pos-1) repeat ( + result := fst + snd + fst := snd + snd := result + ) + return result +) + +n := 4 +fib_rec(n) println +fib_loop(n) println -- cgit v1.2.3