-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.k
67 lines (47 loc) · 833 Bytes
/
test.k
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
fn puts(s: koala_string) {
mut i = 0;
while (i != s.size) {
putchar(s.ptr[i++]);
}
putchar('\n');
return i + 1;
}
fn print_integer(mut n: int) {
if (n == 0) {
putchar('0');
putchar('\n');
return 0;
}
mut rev = 0;
mut rem = 0;
mut i = 0;
while (n) {
rem = n % 10;
rev = rev * 10 + rem;
n /= 10;
++i;
}
while (i--) {
putchar(0x30 + (rev % 10));
rev /= 10;
}
putchar('\n');
return 0;
}
fn fib(n: u32) {
if (n == 0) {
return 0;
}
if (n == 1)
return 1;
return fib(n - 1) + fib(n - 2);
}
fn main() {
puts("Fibonacci sequence:");
mut i = 0;
mut f = fib;
while (i != 20) {
print_integer(f(i++));
}
return 0;
}