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-break / loops-break.om

49 lines · 1142 bytes Raw Blame History
1note Rosetta Code task "Loops/Break": https://rosettacode.org/wiki/Loops/Break
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5note emit writes every byte of a to stdout; a short write is retried, an error exits 1
6fn emit a view uchar * to void
7o = ulong 0
8while lt o len a bound 4096
9k = write 1 a o sub len a o
10if le k 0
11exit 1
12end
13o = add o ulong k
14end
15end
16note emitu writes n in decimal; 20 digits hold every ulong
17fn emitu n ulong to void
18d = new uchar 20 0
19i = ulong 20
20v = n
21while true bound 20
22i = sub i 1
23put d i uchar add rem v 10 48
24v = div v 10
25if eq v 0
26break
27end
28end
29emit part d i sub 20 i
30end
31note a fixed linear congruential generator stands in for a random source (Rosetta asks for
32note random numbers 0..19): x' = (1103515245 x + 12345) mod 2^31, r = (x' / 65536) mod 20.
33note Print r; stop after printing 10; otherwise print the next value too
34fn main to int
35x = ulong 42
36while true bound 1000
37x = and add mul x 1103515245 12345 2147483647
38r = rem div x 65536 20
39emitu r
40emit nl
41if eq r 10
42break
43end
44x = and add mul x 1103515245 12345 2147483647
45emitu rem div x 65536 20
46emit nl
47end
48ret 0
49end