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 / 100-doors.wiki

62 lines · 1136 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 " "
8note emit writes every byte of a to stdout; a short write is retried, an error exits 1
9fn emit a view uchar * to void
10o = ulong 0
11while lt o len a bound 4096
12k = write 1 a o sub len a o
13if le k 0
14exit 1
15end
16o = add o ulong k
17end
18end
19note emitu writes n in decimal; 20 digits hold every ulong
20fn emitu n ulong to void
21d = new uchar 20 0
22i = ulong 20
23v = n
24while true bound 20
25i = sub i 1
26put d i uchar add rem v 10 48
27v = div v 10
28if eq v 0
29break
30end
31end
32emit part d i sub 20 i
33end
34note pass p (1..100) toggles every p-th door; afterwards print the open doors
35fn main to int
36d = new uchar 101 0
37for k ulong 100
38p = add k 1
39i = p
40while le i 100 bound 101
41put d i xor get d i 1
42i = add i p
43end
44end
45f = true
46for i ulong 101
47if eq get d i 1
48if not f
49emit sp
50end
51emitu i
52f = false
53end
54end
55emit nl
56ret 0
57end
58</syntaxhighlight>
59{{out}}
60<pre>
611 4 9 16 25 36 49 64 81 100
62</pre>