-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.tl
52 lines (46 loc) · 1.12 KB
/
utils.tl
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
/* Multiple Function Package File 多函数包文件 */
/* fibonacci with factorial 递归斐波那契数列 */
function factorial_fib(n=10) {
var result = [];
function factor(i) {
if i < 2 {
return 1;
} else {
return factor(i - 2) + factor(i - 1);
}
}
for x from 0 to n {
var result = result + factor(x);
}
return result
}
/* fibonacci with Repeat 循环斐波那契数列 */
function repeat_fib(n=20) {
var result = [];
for i from 0 to n {
if i <= 1 {
var result = result + [1];
} else {
var result = result + (result[i-2] + result[i-1]);
}
}
return result;
}
/* mapping function */
function map(func, ld) {
var result = [];
for x from 0 to length(ld) - 1 {
var result = result + func(ld[x]);
}
return result;
}
/* access array element(s) */
function access(ld, i) {
return ld[i];
}
/* Compute Running Time */
function timer(func) {
var starttime = timestamp();
func();
return timestamp() - starttime;
}