aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-07 18:59:06 +0200
committerlemon <lsof@mailbox.org>2022-08-07 18:59:06 +0200
commit2a4c3689618bef15dc1dc6828fb4d8b8058708fa (patch)
tree0069e56ed2221a3045dbbaefa1acf3f40a83e0fc /bootstrap
parentb3fd91158524dac377ddb756f44f8e3fe67d9cea (diff)
ackermann example
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/ack.cff15
1 files changed, 15 insertions, 0 deletions
diff --git a/bootstrap/ack.cff b/bootstrap/ack.cff
new file mode 100644
index 0000000..233abc2
--- /dev/null
+++ b/bootstrap/ack.cff
@@ -0,0 +1,15 @@
+import "libc.hff";
+
+fn ack(m uint, n uint) uint {
+ if m == 0 { return n + 1; }
+ if n == 0 { return ack(m - 1, 1); }
+ return ack(m - 1, ack(m, n - 1));
+}
+
+extern fn main() void {
+ for let m = 0; m <= 4; ++m {
+ for let n = 0; n < 6 - m; ++n {
+ printf("A(%u,%u) = %u\n", m, n, ack(m, n));
+ }
+ }
+}