diff --git a/tests/bench/010-ackermann.buzz b/tests/bench/010-ackermann.buzz new file mode 100644 index 00000000..a010b1e0 --- /dev/null +++ b/tests/bench/010-ackermann.buzz @@ -0,0 +1,23 @@ +import "std"; + +fun main([str] args) > void { + const m = (if (args.len() > 0) parseInt(args[0]) else null) ?? 3; + const n = (if (args.len() > 1) parseInt(args[1]) else null) ?? 8; + + print("result: {ack(m, n)}"); +} + +fun ack(int m, int n) > int { + if (m == 0) { + return n + 1; + } + + if (n == 0) { + return ack(m: m - 1, n: 1); + } + + return ack( + m: m - 1, + n: ack(m, n: n - 1) + ); +} \ No newline at end of file diff --git a/tests/bench/011-bubble-sort.buzz b/tests/bench/011-bubble-sort.buzz new file mode 100644 index 00000000..220f83cb --- /dev/null +++ b/tests/bench/011-bubble-sort.buzz @@ -0,0 +1,38 @@ +import "std"; + +fun main([str] args) > void { + const max = (if (args.len() > 0) parseInt(args[0]) else null) ?? 750; + + var list = init(max); + + bubblesort(list); + + foreach (int e in list) { + print("{e}"); + } +} + +fun init(int max) > [int] { + [int] list = []; + const f = max - 13; + const h = ((max - 117) * (max - 13)) / max; + + for (int i = 0; i < max; i = i + 1) { + list.append((f * i) % h - (h / 2)); + } + + return list; +} + +fun bubblesort([int] list) > void { + const len = list.len(); + for (int i = 0; i < len - 1; i = i + 1) { + for (int j = 0; j < len - 1; j = j + 1) { + if (list[j] > list[j + 1]) { + const tmp = list[j]; + list[j] = list[j + 1]; + list[j + 1] = tmp; + } + } + } +} \ No newline at end of file