summaryrefslogtreecommitdiff
path: root/io/fib.io
diff options
context:
space:
mode:
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