omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / abc-problem.wiki
| 1 | =={{header|Omegese}}== |
| 2 | {{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}} |
| 3 | Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program. |
| 4 | <syntaxhighlight lang="text"> |
| 5 | om2 |
| 6 | text nl "\n" |
| 7 | text sp " " |
| 8 | text tyes "yes" |
| 9 | text tno "no" |
| 10 | note the 20 blocks, two letters each, separated by spaces |
| 11 | text blocks "BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM" |
| 12 | text w0 "A" |
| 13 | text w1 "BARK" |
| 14 | text w2 "BOOK" |
| 15 | text w3 "TREAT" |
| 16 | text w4 "COMMON" |
| 17 | text w5 "SQUAD" |
| 18 | text w6 "CONFUSE" |
| 19 | global used uchar 20 |
| 20 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 21 | fn emit a view uchar * to void |
| 22 | o = ulong 0 |
| 23 | while lt o len a bound 4096 |
| 24 | k = write 1 a o sub len a o |
| 25 | if le k 0 |
| 26 | exit 1 |
| 27 | end |
| 28 | o = add o ulong k |
| 29 | end |
| 30 | end |
| 31 | fn emitb b bool to void |
| 32 | if b |
| 33 | emit tyes |
| 34 | else |
| 35 | emit tno |
| 36 | end |
| 37 | end |
| 38 | note onblock: block b carries letter c |
| 39 | fn onblock b ulong c uchar to bool |
| 40 | x = mul b 3 |
| 41 | ret or eq get blocks x c eq get blocks add x 1 c |
| 42 | end |
| 43 | note can: letters i.. of w can be spelled with the unused blocks (depth-first, a block is taken |
| 44 | note back when the rest fails) |
| 45 | fn can w view uchar * i ulong to bool |
| 46 | if eq i len w |
| 47 | ret true |
| 48 | end |
| 49 | c = get w i |
| 50 | for b ulong 20 |
| 51 | if eq get used b 0 |
| 52 | if onblock b c |
| 53 | put used b 1 |
| 54 | if can w add i 1 |
| 55 | ret true |
| 56 | end |
| 57 | put used b 0 |
| 58 | end |
| 59 | end |
| 60 | end |
| 61 | ret false |
| 62 | end |
| 63 | fn show w view uchar * to void |
| 64 | for b ulong 20 |
| 65 | put used b 0 |
| 66 | end |
| 67 | emit w |
| 68 | emit sp |
| 69 | emitb can w 0 |
| 70 | emit nl |
| 71 | end |
| 72 | fn main to int |
| 73 | show w0 |
| 74 | show w1 |
| 75 | show w2 |
| 76 | show w3 |
| 77 | show w4 |
| 78 | show w5 |
| 79 | show w6 |
| 80 | ret 0 |
| 81 | end |
| 82 | </syntaxhighlight> |
| 83 | {{out}} |
| 84 | <pre> |
| 85 | A yes |
| 86 | BARK yes |
| 87 | BOOK no |
| 88 | TREAT yes |
| 89 | COMMON no |
| 90 | SQUAD yes |
| 91 | CONFUSE yes |
| 92 | </pre> |