blob: 34519e605065d55049cb814452adfa9c6bbc1e32 (
plain) (
blame)
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
|
import "!stdlib.pry";
let main = () => i64 {
let factorial = (n: i64) => i64 {
let f = (acc: i64, n: i64) => i64 {
if n == 0 {
return acc;
};
return f(acc * n, n - 1);
};
return f(1, n);
};
let is_even = (n: i64) => bool {
if n % 2 == 0 {
return true;
};
return false;
};
let sum_if = (predicate: (i64) => bool, limit: i64) => i64 {
let sum = 0;
let i = 0;
while i < limit {
if predicate(i) {
sum = sum + i;
};
i = i + 1;
};
return sum;
};
let fact_val = factorial(6);
printf("%d\n", fact_val);
let even_sum = sum_if(is_even, 20);
printf("%d\n", even_sum);
return 0;
};
/*
Expected stdout:
720
90
Expected return: 0
*/
|