interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / tasks / loops-n-plus-one-half / loops-n-plus-one-half.om

45 lines · 888 bytes Raw Blame History
1note Rosetta Code task "Loops/N plus one half": https://rosettacode.org/wiki/Loops/N_plus_one_half
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sep ", "
6note emit writes every byte of a to stdout; a short write is retried, an error exits 1
7fn emit a view uchar * to void
8o = ulong 0
9while lt o len a bound 4096
10k = write 1 a o sub len a o
11if le k 0
12exit 1
13end
14o = add o ulong k
15end
16end
17note emitu writes n in decimal; 20 digits hold every ulong
18fn emitu n ulong to void
19d = new uchar 20 0
20i = ulong 20
21v = n
22while true bound 20
23i = sub i 1
24put d i uchar add rem v 10 48
25v = div v 10
26if eq v 0
27break
28end
29end
30emit part d i sub 20 i
31end
32note the loop writes the number, leaves at 10, else the separator: the last pass is half a pass
33fn main to int
34i = ulong 1
35while true bound 100
36emitu i
37if eq i 10
38break
39end
40emit sep
41i = add i 1
42end
43emit nl
44ret 0
45end