Tweaked the runner test, should be orders of magnitude faster

This commit is contained in:
2023-02-14 16:16:48 +00:00
parent 3312a38c7c
commit 913738a4d1
2 changed files with 16 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
//WARNING: please think twice before using this in a test
fn fib(n : int) {
if (n < 2) return n;
return fib(n-1) + fib(n-2);

View File

@@ -1,12 +1,21 @@
//memoize the fib function
var memo: [int : int] = [:];
fn fib(n : int) {
if (n < 2) {
return n;
}
return fib(n-1) + fib(n-2);
var result = memo[n];
if (result == null) {
result = fib(n-1) + fib(n-2);
memo[n] = result;
}
return result;
}
for (var i = 0; i < 20; i++) {
for (var i = 0; i < 40; i++) {
var res = fib(i);
print string i + ": " + string res;
}