summaryrefslogtreecommitdiff
path: root/miralib/ex/fibs.m
diff options
context:
space:
mode:
Diffstat (limited to 'miralib/ex/fibs.m')
-rw-r--r--miralib/ex/fibs.m16
1 files changed, 16 insertions, 0 deletions
diff --git a/miralib/ex/fibs.m b/miralib/ex/fibs.m
new file mode 100644
index 0000000..39c805d
--- /dev/null
+++ b/miralib/ex/fibs.m
@@ -0,0 +1,16 @@
+||This program tabulates the values of `fib i' a function for computing
+||fibonacci numbers, in a list `fibs'. Because the function is memoised
+||(i.e. it uses table lookup when it recurses) it runs in linear time.
+||To see the fibonacci numbers say.
+|| test
+
+fibs = map fib [0..]
+fib 0 = 0
+fib 1 = 1
+fib (n+2) = fibs!(n+1) + fibs!n
+
+test = layn (map shownum fibs)
+
+||P.S. There is a more direct way of defining fibs, using a list comprehension
+|| fibs = [a | (a,b) <- (0,1), (b,a+b) .. ]
+||this also runs in linear time