-
-
Notifications
You must be signed in to change notification settings - Fork 467
/
fibonnaci.zep
98 lines (83 loc) · 1.24 KB
/
fibonnaci.zep
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
namespace Stub;
class Fibonnaci
{
public function fibInt()
{
int x, y, n, z;
let z = 0,
x = 1,
y = 2,
n = 10;
while z < n {
let z = x + y,
x = y,
y = z;
}
return z;
}
public function fibDouble()
{
double x, y, n, z;
let z = 0.0,
x = 1.0,
y = 2.0,
n = 10.0;
while z < n {
let z = x + y,
x = y,
y = z;
}
return z;
}
public function fibArray()
{
var fib, a, b, c;
int i, n, k, j;
let fib = [0, 1],
i = 2,
n = 10;
while i < n {
let k = i - 1,
j = i - 2,
a = fib[k],
b = fib[j],
c = a + b,
fib[i] = c,
i++;
}
return fib;
}
public function fibArray2()
{
var fib; int i, n;
let fib = [0, 1], i = 2, n = 10;
while i < n {
let fib[i] = fib[i - 1] + fib[i - 2], i++;
}
return fib;
}
private function fibonacciRecursive(int n)
{
if n == 0 {
return 0;
} else {
if n == 1 {
return 1;
} else {
return this->fibonacciRecursive(n - 1) + this->fibonacciRecursive(n - 2);
}
}
}
private final function fibonacciFinalRecursive(int n)
{
if n == 0 {
return 0;
} else {
if n == 1 {
return 1;
} else {
return this->fibonacciFinalRecursive(n - 1) + this->fibonacciFinalRecursive(n - 2);
}
}
}
}