root/trunk/samples/ackermann.md

Revision 292, 336 bytes (checked in by JarrettBillingsley, 7 months ago)

Closes #65. Also fixed a bug in the regexp.email predefined regexp, and a small bug in dumpVal.

Line 
1 module ackermann
2
3 local function Ack(M, N)
4     if(M == 0)
5         return N + 1
6     else if(N == 0)
7         return Ack(M - 1, 1)
8     else
9         return Ack(M - 1, Ack(M, (N - 1)))
10
11 function main(N)
12 {
13     local n = 1
14
15     if(isString(N))
16     {
17         n = toInt(N)
18
19         if(n < 1)
20             n = 1
21     }
22
23     writefln("n = ", n)
24     writefln("Ack(3, ", n, "): ", Ack(3, n))
25 }
Note: See TracBrowser for help on using the browser.