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 / power-set.wiki

85 lines · 1395 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 " "
8text minus "-"
9text tlb "{"
10text trb "}"
11text tcomma ", "
12text tcount "subsets: "
13note emit writes every byte of a to stdout; a short write is retried, an error exits 1
14fn emit a view uchar * to void
15o = ulong 0
16while lt o len a bound 4096
17k = write 1 a o sub len a o
18if le k 0
19exit 1
20end
21o = add o ulong k
22end
23end
24note emitu writes n in decimal; 20 digits hold every ulong
25fn emitu n ulong to void
26d = new uchar 20 0
27i = ulong 20
28v = n
29while true bound 20
30i = sub i 1
31put d i uchar add rem v 10 48
32v = div v 10
33if eq v 0
34break
35end
36end
37emit part d i sub 20 i
38end
39note subset m of {1, 2, 3, 4} holds element i+1 when bit i of m is set; the 16 subsets are listed in
40note the order of m, which is binary counting
41fn subset m ulong to void
42emit tlb
43first = true
44for i ulong 4
45if ne and shr m i 1 0
46if not first
47emit tcomma
48end
49emitu add i 1
50first = false
51end
52end
53emit trb
54emit nl
55end
56fn main to int
57for m ulong 16
58subset m
59end
60emit tcount
61emitu 16
62emit nl
63ret 0
64end
65</syntaxhighlight>
66{{out}}
67<pre>
68{}
69{1}
70{2}
71{1, 2}
72{3}
73{1, 3}
74{2, 3}
75{1, 2, 3}
76{4}
77{1, 4}
78{2, 4}
79{1, 2, 4}
80{3, 4}
81{1, 3, 4}
82{2, 3, 4}
83{1, 2, 3, 4}
84subsets: 16
85</pre>