interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / si / rosetta / tasks / 100-doors / 100-doors.om

55 lines · 966 bytes Raw Blame History
1note Rosetta Code task "100 doors": https://rosettacode.org/wiki/100_doors
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
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 pass p (1..100) toggles every p-th door; afterwards print the open doors
33fn main to int
34d = new uchar 101 0
35for k ulong 100
36p = add k 1
37i = p
38while le i 100 bound 101
39put d i xor get d i 1
40i = add i p
41end
42end
43f = true
44for i ulong 101
45if eq get d i 1
46if not f
47emit sp
48end
49emitu i
50f = false
51end
52end
53emit nl
54ret 0
55end