-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.ds
More file actions
41 lines (41 loc) · 725 Bytes
/
test.ds
File metadata and controls
41 lines (41 loc) · 725 Bytes
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
Int factorial(Int n) {
if(n<2) {
return 1;
} else {
return n * factorial(n-1);
}
}
Int fibbonaci(Int n) {
if(n<1) {
return 0;
} else if(n<2) {
return 1;
} else {
return fibbonaci(n-1) + fibbonaci(n-2);
}
}
Real fibbonaciLoop(Int n) {
if(n<1) {
return 0.0;
} else if(n<2) {
return 1.0;
} else {
Real a = 0.0;
Real b = 1.0;
Real c = 0.0;
Int i = 1;
while(i<n) {
i++;
c = a + b;
a = b;
b = c;
}
return c;
}
}
println("calculating factorial");
println("factorial(10)="+factorial(10));
println("calculating fibbonaci (fast O(n) way)");
println("fibbonaciLoop(15)="+fibbonaciLoop(15));
println("calculating fibbonaci (slow O(phi^n) way)");
println("fibbonaci(15)="+fibbonaci(15));