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

62 lines · 1127 bytes Raw Blame History
1note Rosetta Code task "Power set": https://rosettacode.org/wiki/Power_set
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text minus "-"
7text tlb "{"
8text trb "}"
9text tcomma ", "
10text tcount "subsets: "
11note emit writes every byte of a to stdout; a short write is retried, an error exits 1
12fn emit a view uchar * to void
13o = ulong 0
14while lt o len a bound 4096
15k = write 1 a o sub len a o
16if le k 0
17exit 1
18end
19o = add o ulong k
20end
21end
22note emitu writes n in decimal; 20 digits hold every ulong
23fn emitu n ulong to void
24d = new uchar 20 0
25i = ulong 20
26v = n
27while true bound 20
28i = sub i 1
29put d i uchar add rem v 10 48
30v = div v 10
31if eq v 0
32break
33end
34end
35emit part d i sub 20 i
36end
37note subset m of {1, 2, 3, 4} holds element i+1 when bit i of m is set; the 16 subsets are listed in
38note the order of m, which is binary counting
39fn subset m ulong to void
40emit tlb
41first = true
42for i ulong 4
43if ne and shr m i 1 0
44if not first
45emit tcomma
46end
47emitu add i 1
48first = false
49end
50end
51emit trb
52emit nl
53end
54fn main to int
55for m ulong 16
56subset m
57end
58emit tcount
59emitu 16
60emit nl
61ret 0
62end