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 / number-names.wiki

147 lines · 2914 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 hy "-"
9text colon ": "
10text ones "zero\none\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\neleven\ntwelve\nthirteen\nfourteen\nfifteen\nsixteen\nseventeen\neighteen\nnineteen\n"
11text tens "twenty\nthirty\nforty\nfifty\nsixty\nseventy\neighty\nninety\n"
12text scales "thousand\nmillion\nbillion\ntrillion\nquadrillion\nquintillion\n"
13text hund " hundred"
14note emit writes every byte of a to stdout; a short write is retried, an error exits 1
15fn emit a view uchar * to void
16o = ulong 0
17while lt o len a bound 4096
18k = write 1 a o sub len a o
19if le k 0
20exit 1
21end
22o = add o ulong k
23end
24end
25note emitu writes n in decimal; 20 digits hold every ulong
26fn emitu n ulong to void
27d = new uchar 20 0
28i = ulong 20
29v = n
30while true bound 20
31i = sub i 1
32put d i uchar add rem v 10 48
33v = div v 10
34if eq v 0
35break
36end
37end
38emit part d i sub 20 i
39end
40note word writes element k of a newline-terminated list
41fn word t view uchar * k ulong to void
42s = ulong 0
43m = ulong 0
44for i ulong len t
45if eq get t i 10
46if eq m k
47emit part t s sub i s
48ret
49end
50m = add m 1
51s = add i 1
52end
53end
54trap 9
55end
56note three writes 1..999 in words: hundreds, then the rest (under 20 by name, else tens-ones)
57fn three g ulong to void
58h = div g 100
59r = rem g 100
60if gt h 0
61word ones h
62emit hund
63if gt r 0
64emit sp
65end
66end
67if and gt r 0 lt r 20
68word ones r
69end
70if ge r 20
71word tens sub div r 10 2
72if gt rem r 10 0
73emit hy
74word ones rem r 10
75end
76end
77end
78note spell splits n into groups of three digits and writes each non-zero one with its scale
79fn spell n ulong to void
80if eq n 0
81word ones 0
82ret
83end
84g = new ulong 7 0
85v = n
86for i ulong 7
87put g i rem v 1000
88v = div v 1000
89end
90first = true
91for k ulong 7
92i = sub 6 k
93x = get g i
94if gt x 0
95if not first
96emit sp
97end
98three x
99if gt i 0
100emit sp
101word scales sub i 1
102end
103first = false
104end
105end
106end
107fn show n ulong to void
108emitu n
109emit colon
110spell n
111emit nl
112end
113fn main to int
114show 0
115show 7
116show 13
117show 21
118show 99
119show 100
120show 101
121show 999
122show 1000
123show 1001
124show 12345
125show 1000000
126show 1234567890
127show 18446744073709551615
128ret 0
129end
130</syntaxhighlight>
131{{out}}
132<pre>
1330: zero
1347: seven
13513: thirteen
13621: twenty-one
13799: ninety-nine
138100: one hundred
139101: one hundred one
140999: nine hundred ninety-nine
1411000: one thousand
1421001: one thousand one
14312345: twelve thousand three hundred forty-five
1441000000: one million
1451234567890: one billion two hundred thirty-four million five hundred sixty-seven thousand eight hundred ninety
14618446744073709551615: eighteen quintillion four hundred forty-six quadrillion seven hundred forty-four trillion seventy-three billion seven hundred nine million five hundred fifty-one thousand six hundred fifteen
147</pre>