summaryrefslogtreecommitdiff
path: root/io/fib.io
diff options
context:
space:
mode:
authorGuillermo Ramos2012-04-02 20:48:33 +0200
committerGuillermo Ramos2012-04-02 20:48:33 +0200
commit8ae4691e677414843cf3a84d4327d303fe3e2f41 (patch)
tree6007373b702ece4100819606a82ecbae76ff1dd5 /io/fib.io
parentfdd1e7abacd96d9bd49c13b2ecfcfe897546acae (diff)
download7l-8ae4691e677414843cf3a84d4327d303fe3e2f41.tar.gz
[Io] Día 2
Diffstat (limited to 'io/fib.io')
-rw-r--r--io/fib.io23
1 files changed, 23 insertions, 0 deletions
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