fib
This commit is contained in:
@ -1,39 +1,63 @@
|
|||||||
(* TEST: [-asc -tc -cg -ir] *)
|
|
||||||
|
|
||||||
#include "std.alpha"
|
#include "std.alpha"
|
||||||
|
|
||||||
function entry : string2integer
|
function entry : string2integer
|
||||||
function Fib : integer2integer
|
function fib : integer2integer
|
||||||
|
|
||||||
Fib(i) := {
|
fib(i) := {
|
||||||
[integer: a; integer: b ; Boolean: d ; integer: c]
|
[ integer: a; integer: b; integer: count ]
|
||||||
(*if( i = 0 ) then {
|
|
||||||
return 7;
|
|
||||||
} else {
|
|
||||||
i := i;
|
|
||||||
}*)
|
|
||||||
(*b := b | (a & c);
|
|
||||||
b := 2 < 3;*)
|
|
||||||
|
|
||||||
(* `if(i = 1) then { return 1; } else {
|
a := 1;
|
||||||
return Fib(i - 1) + Fib(i - 2);
|
b := 2;
|
||||||
}
|
|
||||||
*)
|
|
||||||
|
|
||||||
a := 0;
|
if (i = 0) then {
|
||||||
b := 1;
|
return 0;
|
||||||
while(0 < i) {
|
} else {
|
||||||
c := a + b;
|
a := a;
|
||||||
a := b;
|
}
|
||||||
b := c;
|
|
||||||
}
|
if (i = 1) then {
|
||||||
return c;
|
return 1;
|
||||||
|
} else {
|
||||||
|
a := a;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i = 2) then {
|
||||||
|
return 2;
|
||||||
|
} else {
|
||||||
|
a := a;
|
||||||
|
}
|
||||||
|
|
||||||
|
count := 2;
|
||||||
|
while (count < i) {
|
||||||
|
|
||||||
|
count := count + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry (arg) := {
|
entry (arg) := {
|
||||||
[ integer: x; integer: y ]
|
[ integer: result; integer: input; integer: fibValue]
|
||||||
x := 2;
|
|
||||||
(* x := Fib(2);*)
|
result := printC('E');
|
||||||
y := printInteger(Fib(3));
|
result := printC('n');
|
||||||
return 1;
|
result := printC('t');
|
||||||
|
result := printC('e');
|
||||||
|
result := printC('r');
|
||||||
|
result := printC(' ');
|
||||||
|
result := printC('N');
|
||||||
|
result := printC('u');
|
||||||
|
result := printC('m');
|
||||||
|
result := printC('b');
|
||||||
|
result := printC('e');
|
||||||
|
result := printC('r');
|
||||||
|
result := printC(':');
|
||||||
|
result := printC(' ');
|
||||||
|
|
||||||
|
input := inI(1);
|
||||||
|
fibValue := fib(input);
|
||||||
|
|
||||||
|
result := printI(fibValue);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user