Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-rosetta/blob/main/tasks/power-set/power-set.om # omega-rosetta aien-dev/omega-rosetta Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-rosetta / tasks / power-set / power-set.om` 62 lines ยท 1127 bytes Raw Blame History 1 note Rosetta Code task "Power set": https://rosettacode.org/wiki/Power_set 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 om2 4 text nl "\n" 5 text sp " " 6 text minus "-" 7 text tlb "{" 8 text trb "}" 9 text tcomma ", " 10 text tcount "subsets: " 11 note emit writes every byte of a to stdout; a short write is retried, an error exits 1 12 fn emit a view uchar * to void 13 o = ulong 0 14 while lt o len a bound 4096 15 k = write 1 a o sub len a o 16 if le k 0 17 exit 1 18 end 19 o = add o ulong k 20 end 21 end 22 note emitu writes n in decimal; 20 digits hold every ulong 23 fn emitu n ulong to void 24 d = new uchar 20 0 25 i = ulong 20 26 v = n 27 while true bound 20 28 i = sub i 1 29 put d i uchar add rem v 10 48 30 v = div v 10 31 if eq v 0 32 break 33 end 34 end 35 emit part d i sub 20 i 36 end 37 note subset m of {1, 2, 3, 4} holds element i+1 when bit i of m is set; the 16 subsets are listed in 38 note the order of m, which is binary counting 39 fn subset m ulong to void 40 emit tlb 41 first = true 42 for i ulong 4 43 if ne and shr m i 1 0 44 if not first 45 emit tcomma 46 end 47 emitu add i 1 48 first = false 49 end 50 end 51 emit trb 52 emit nl 53 end 54 fn main to int 55 for m ulong 16 56 subset m 57 end 58 emit tcount 59 emitu 16 60 emit nl 61 ret 0 62 end