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 / abc-problem / abc-problem.om

79 lines · 1414 bytes Raw Blame History
1note Rosetta Code task "ABC problem": https://rosettacode.org/wiki/ABC_problem
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text sp " "
6text tyes "yes"
7text tno "no"
8note the 20 blocks, two letters each, separated by spaces
9text blocks "BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM"
10text w0 "A"
11text w1 "BARK"
12text w2 "BOOK"
13text w3 "TREAT"
14text w4 "COMMON"
15text w5 "SQUAD"
16text w6 "CONFUSE"
17global used uchar 20
18note emit writes every byte of a to stdout; a short write is retried, an error exits 1
19fn emit a view uchar * to void
20o = ulong 0
21while lt o len a bound 4096
22k = write 1 a o sub len a o
23if le k 0
24exit 1
25end
26o = add o ulong k
27end
28end
29fn emitb b bool to void
30if b
31emit tyes
32else
33emit tno
34end
35end
36note onblock: block b carries letter c
37fn onblock b ulong c uchar to bool
38x = mul b 3
39ret or eq get blocks x c eq get blocks add x 1 c
40end
41note can: letters i.. of w can be spelled with the unused blocks (depth-first, a block is taken
42note back when the rest fails)
43fn can w view uchar * i ulong to bool
44if eq i len w
45ret true
46end
47c = get w i
48for b ulong 20
49if eq get used b 0
50if onblock b c
51put used b 1
52if can w add i 1
53ret true
54end
55put used b 0
56end
57end
58end
59ret false
60end
61fn show w view uchar * to void
62for b ulong 20
63put used b 0
64end
65emit w
66emit sp
67emitb can w 0
68emit nl
69end
70fn main to int
71show w0
72show w1
73show w2
74show w3
75show w4
76show w5
77show w6
78ret 0
79end