summaryrefslogtreecommitdiff
path: root/tigrou/fibo/fibo.tih
diff options
context:
space:
mode:
Diffstat (limited to 'tigrou/fibo/fibo.tih')
-rw-r--r--tigrou/fibo/fibo.tih18
1 files changed, 18 insertions, 0 deletions
diff --git a/tigrou/fibo/fibo.tih b/tigrou/fibo/fibo.tih
new file mode 100644
index 0000000..72123a6
--- /dev/null
+++ b/tigrou/fibo/fibo.tih
@@ -0,0 +1,18 @@
+function fibo(n : int) : int =
+ if n < 0 then
+ -1
+ else
+ if n <= 1 then
+ n
+ else
+ let
+ var curr := 0
+ var prev1 := 1
+ var prev2 := 0
+ in
+ (for i := 2 to n do
+ (curr := prev1 + prev2;
+ prev2 := prev1;
+ prev1 := curr));
+ curr
+ end