-
Notifications
You must be signed in to change notification settings - Fork 0
/
fibonacci.janus
69 lines (62 loc) · 1.26 KB
/
fibonacci.janus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Various Fibonacci calculations.
// Recursive Fibonacci procedure
procedure fib(int n, int x1, int x2)
if n=0 then
x1 += 1
x2 += 1
else
n -= 1
call fib(n, x1, x2)
x1 += x2
x1 <=> x2
fi x1=x2
// Returns a single Fibonacci number (r) as well
// as the initial input (n, x1 and x2).
procedure fiba(int r, int n, int x1, int x2)
call fib(n, x1, x2)
r += x1
uncall fib(n, x1, x2)
// Returns a single Fibonacci number (r).
// All other variables must be empty (0).
// Works for n > 0.
procedure fibb(int r, int n, int x1, int x2)
x1 += 1
x2 += 1
local int i = 0
from i = 0 do
x1 += x2
x1 <=> x2
i += 1
until i = n
delocal int i = n
r += x1
from x1 = r do
x1 <=> x2
x1 -= x2
n -= 1
until x1 = x2
x1 -= 1
x2 -= 1
// Main procedure
// Sets variables and calls procedures.
procedure main()
// Variables for fib
int n
int x1
int x2
// Variables for fiba
int ar
int an
int ax1
int ax2
// Variables for fibb
int br
int bn
int bx1
int bx2
n += 4
call fib(n, x1, x2)
an += 4
call fiba(ar, an, ax1, ax2)
bn += 4
call fibb(br, bn, bx1, bx2)