summary refs log tree commit diff stats
path: root/tests/misc/tack.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/misc/tack.nim')
-rw-r--r--tests/misc/tack.nim19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/misc/tack.nim b/tests/misc/tack.nim
new file mode 100644
index 000000000..458395ef6
--- /dev/null
+++ b/tests/misc/tack.nim
@@ -0,0 +1,19 @@
+discard """
+  output: "125"
+"""
+# the Ackermann function
+
+proc ack(x, y: int): int =
+  if x != 0:
+    if y != 0:
+      return ack(x-1, ack(x, y-1))
+    return ack(x-1, 1)
+  else:
+    return y + 1
+#  if x == 0: return y + 1
+#  elif y == 0: return ack(x-1, 1)
+#  else: return ack(x-1, ack(x, y-1))
+
+# echo(ack(0, 0))
+write(stdout, ack(3, 4)) #OUT 125
+write stdout, "\n"