-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest1.tiny
55 lines (38 loc) · 869 Bytes
/
test1.tiny
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
func fib(n) {
a := 0
b := 1
for i := 0; i < n; i += 1 {
new_a := b
b += a
a = new_a
}
return b
}
n := input("How many fibonacci numbers do you want? ")
n = ston(n)
print("Computing...")
nums := array()
array_resize(nums, n)
ticks := perf_count()
for i := 0; i < n; i += 1 {
val := fib(i)
array_set(nums, i, val)
}
elapsed := perf_count() - ticks
print("Done computing numbers.")
printf("That took %g seconds.\n", elapsed / perf_freq())
filename := input("Where would you like to output them? ")
file := fopen(filename, "w")
if not file {
printf("Couldn't open file '%s' for writing.\n", filename)
exit(1)
}
ticks = perf_count()
for i = 0; i < n; i += 1 {
sn := ntos(array_get(nums, i))
fwrite(file, strcat(sn, "\n"))
}
elapsed = perf_count() - ticks
fclose(file)
print("Done.")
printf("That took %g seconds.\n", elapsed / perf_freq())