interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / ackermann-function.wiki

83 lines · 1414 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text pre "A("
8text cm ", "
9text post ") = "
10note emit writes every byte of a to stdout; a short write is retried, an error exits 1
11fn emit a view uchar * to void
12o = ulong 0
13while lt o len a bound 4096
14k = write 1 a o sub len a o
15if le k 0
16exit 1
17end
18o = add o ulong k
19end
20end
21note emitu writes n in decimal; 20 digits hold every ulong
22fn emitu n ulong to void
23d = new uchar 20 0
24i = ulong 20
25v = n
26while true bound 20
27i = sub i 1
28put d i uchar add rem v 10 48
29v = div v 10
30if eq v 0
31break
32end
33end
34emit part d i sub 20 i
35end
36note recursive, as the task asks; program mode allows recursion, the 8 MiB stack bounds its depth
37fn ack m ulong n ulong to ulong
38if eq m 0
39ret add n 1
40end
41if eq n 0
42ret ack sub m 1 1
43end
44ret ack sub m 1 ack m sub n 1
45end
46fn main to int
47for m ulong 4
48for n ulong 5
49emit pre
50emitu m
51emit cm
52emitu n
53emit post
54emitu ack m n
55emit nl
56end
57end
58ret 0
59end
60</syntaxhighlight>
61{{out}}
62<pre>
63A(0, 0) = 1
64A(0, 1) = 2
65A(0, 2) = 3
66A(0, 3) = 4
67A(0, 4) = 5
68A(1, 0) = 2
69A(1, 1) = 3
70A(1, 2) = 4
71A(1, 3) = 5
72A(1, 4) = 6
73A(2, 0) = 3
74A(2, 1) = 5
75A(2, 2) = 7
76A(2, 3) = 9
77A(2, 4) = 11
78A(3, 0) = 5
79A(3, 1) = 13
80A(3, 2) = 29
81A(3, 3) = 61
82A(3, 4) = 125
83</pre>