Commits

Antoine Pietri committed d4f5811

added some recursive examples

Comments (0)

Files changed (2)

examples/ackermann.bl

+ackermann(m,n)
+{
+    if (m == 0)
+    {
+        return n + 1;
+    }
+    else
+    {
+        if (n == 0)
+        {
+            return ackermann(m - 1, 1);
+        }
+        else
+        {
+            return ackermann(m - 1, ackermann(m, n - 1));
+        }
+    }
+}
+
+main()
+{
+    vars a, b;
+    a = read();
+    b = read();
+    write(ackermann(a, b));
+}
+fact(x)
+{
+    if (x < 0)
+    {
+        return 0;
+    }
+    else
+    {
+        if (x == 0 || x == 1)
+        {
+            return 1;
+        }
+        else
+        {
+            return x * fact(x - 1);
+        }
+    }
+}
+
+main()
+{
+    vars a;
+    a = read();
+    write(fact(a));
+}