[gesamt] Added ag/codea/codeb testcases
[testub10.git] / gesamt / codeb_georg_fib_043.0
diff --git a/gesamt/codeb_georg_fib_043.0 b/gesamt/codeb_georg_fib_043.0
new file mode 100644 (file)
index 0000000..4db524a
--- /dev/null
@@ -0,0 +1,22 @@
+/* fibonacci */
+
+/* F_0 = 0 */
+/* F_1 = 1 */
+/* F_n = F_{n-1} + F_{n-2} */
+
+struct f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 end;
+
+method fib(x)
+       var t := this;
+       if x < 0 then return -1; end;   t.f0 := 0;
+       if x < 1 then return f0; end;   t.f1 := 1;
+       if x < 2 then return f1; end;   t.f2 := t.f0-(0-t.f1);  t := t--8;
+       if x < 3 then return f2; end;   t.f2 := t.f0-(0-t.f1);  t := t--8;
+       if x < 4 then return f3; end;   t.f2 := t.f0-(0-t.f1);  t := t--8;
+       if x < 5 then return f4; end;   t.f2 := t.f0-(0-t.f1);  t := t--8;
+       if x < 6 then return f5; end;   t.f2 := t.f0-(0-t.f1);  t := t--8;
+       if x < 7 then return f6; end;   t.f2 := t.f0-(0-t.f1);  t := t--8;
+       if x < 8 then return f7; end;   t.f2 := t.f0-(0-t.f1);  t := t--8;
+       if x < 9 then return f8; end;   t.f2 := t.f0-(0-t.f1);  t := t--8;
+       return f9;
+end;