interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / 99-bottles-of-beer / 99-bottles-of-beer.om

64 lines · 1074 bytes Raw Blame History
1note Rosetta Code task "99 bottles of beer": https://rosettacode.org/wiki/99_bottles_of_beer
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text nomore "No more"
6text b1 " bottle"
7text bn " bottles"
8text wall " of beer on the wall\n"
9text beer " of beer\n"
10text take "Take one down, pass it around\n"
11note emit writes every byte of a to stdout; a short write is retried, an error exits 1
12fn emit a view uchar * to void
13o = ulong 0
14while lt o len a bound 4096
15k = write 1 a o sub len a o
16if le k 0
17exit 1
18end
19o = add o ulong k
20end
21end
22note emitu writes n in decimal; 20 digits hold every ulong
23fn emitu n ulong to void
24d = new uchar 20 0
25i = ulong 20
26v = n
27while true bound 20
28i = sub i 1
29put d i uchar add rem v 10 48
30v = div v 10
31if eq v 0
32break
33end
34end
35emit part d i sub 20 i
36end
37fn bottles n ulong to void
38if eq n 0
39emit nomore
40else
41emitu n
42end
43if eq n 1
44emit b1
45else
46emit bn
47end
48end
49fn main to int
50for i ulong 99
51n = sub 99 i
52bottles n
53emit wall
54bottles n
55emit beer
56emit take
57bottles sub n 1
58emit wall
59if lt i 98
60emit nl
61end
62end
63ret 0
64end