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 / bell-numbers.wiki

132 lines · 2803 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 sp " "
8text tri "first 10 rows of the Bell triangle:\n"
9text first "first 15 Bell numbers:"
10text b49 "B(49), the 50th Bell number: "
11note a triangle row of up to 50 entries; entry e is 6 limbs base 10^9 at 6e..6e+5, least significant first
12note 6 limbs hold below 10^54; the largest entry needed, in row 49, is below B(50) < 2 * 10^47
13global pv ulong 300
14global cu ulong 300
15note emit writes every byte of a to stdout; a short write is retried, an error exits 1
16fn emit a view uchar * to void
17o = ulong 0
18while lt o len a bound 4096
19k = write 1 a o sub len a o
20if le k 0
21exit 1
22end
23o = add o ulong k
24end
25end
26note emitu writes n in decimal; 20 digits hold every ulong
27fn emitu n ulong to void
28d = new uchar 20 0
29i = ulong 20
30v = n
31while true bound 20
32i = sub i 1
33put d i uchar add rem v 10 48
34v = div v 10
35if eq v 0
36break
37end
38end
39emit part d i sub 20 i
40end
41note row i of the Bell triangle starts with the last entry of row i - 1; each next entry adds the entry
42note to its left and the entry above that one. Row i - 1 sits in pv and row i is built in cu, then copied
43fn bellrow i ulong to void
44for l ulong 6
45put cu l get pv add mul sub i 1 6 l
46end
47for j ulong i
48c = ulong 0
49for l ulong 6
50o = add mul j 6 l
51s = add get cu o c
52s = add s get pv o
53put cu add o 6 rem s 1000000000
54c = div s 1000000000
55end
56end
57for t ulong mul add i 1 6
58put pv t get cu t
59end
60end
61note pv entry 0 in decimal: the top non-zero limb, then each lower limb padded to 9 digits
62fn emitb to void
63k = ulong 5
64while and gt k 0 eq get pv k 0 bound 6
65k = sub k 1
66end
67emitu get pv k
68for t ulong k
69v = get pv sub sub k 1 t
70d = ulong 100000000
71while gt d 0 bound 9
72emitu rem div v d 10
73d = div d 10
74end
75end
76end
77fn main to int
78bs = new ulong 15 0
79put pv 0 1
80put bs 0 1
81emit tri
82emitu 1
83emit nl
84i = ulong 1
85while le i 49 bound 49
86bellrow i
87if lt i 10
88for j ulong add i 1
89if gt j 0
90emit sp
91end
92emitu get pv mul j 6
93end
94emit nl
95end
96if lt i 15
97put bs i get pv 0
98end
99if lt i 49
100i = add i 1
101else
102break
103end
104end
105emit first
106for j ulong 15
107emit sp
108emitu get bs j
109end
110emit nl
111emit b49
112emitb
113emit nl
114ret 0
115end
116</syntaxhighlight>
117{{out}}
118<pre>
119first 10 rows of the Bell triangle:
1201
1211 2
1222 3 5
1235 7 10 15
12415 20 27 37 52
12552 67 87 114 151 203
126203 255 322 409 523 674 877
127877 1080 1335 1657 2066 2589 3263 4140
1284140 5017 6097 7432 9089 11155 13744 17007 21147
12921147 25287 30304 36401 43833 52922 64077 77821 94828 115975
130first 15 Bell numbers: 1 1 2 5 15 52 203 877 4140 21147 115975 678570 4213597 27644437 190899322
131B(49), the 50th Bell number: 10726137154573358400342215518590002633917247281
132</pre>