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 / determine-if-a-string-is-squeezable / determine-if-a-string-is-squeezable.om

84 lines · 1791 bytes Raw Blame History
1note Rosetta Code task "Determine if a string is squeezable": https://rosettacode.org/wiki/Determine_if_a_string_is_squeezable
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text lq "<<<"
6text rq ">>>"
7text tlen " length "
8text tch "squeeze '"
9text tq "'\n"
10text c0 "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln "
11text c1 "..1111111111111111111111111111111111111111111111111111111111111117777888"
12text c2 "I never give 'em hell, I just tell the truth, and they think it's hell. "
13text c3 " --- Harry S Truman "
14text chars "-7. -r"
15note emit writes every byte of a to stdout; a short write is retried, an error exits 1
16fn emit a view uchar * to void
17o = ulong 0
18while lt o len a bound 4096
19k = write 1 a o sub len a o
20if le k 0
21exit 1
22end
23o = add o ulong k
24end
25end
26note emitu writes n in decimal; 20 digits hold every ulong
27fn emitu n ulong to void
28d = new uchar 20 0
29i = ulong 20
30v = n
31while true bound 20
32i = sub i 1
33put d i uchar add rem v 10 48
34v = div v 10
35if eq v 0
36break
37end
38end
39emit part d i sub 20 i
40end
41note emitc writes one byte
42fn emitc c uchar to void
43b = new uchar 1 0
44put b 0 c
45emit b
46end
47fn line a view uchar * to void
48emit lq
49emit a
50emit rq
51emit tlen
52emitu len a
53emit nl
54end
55note squeeze drops a byte equal to ch when the byte before it is also ch
56fn squeeze a view uchar * ch uchar to void
57o = new uchar 256 0
58n = ulong 0
59for i ulong len a
60c = get a i
61k = true
62if and gt i 0 eq c ch
63k = ne get a sub i 1 ch
64end
65if k
66put o n c
67n = add n 1
68end
69end
70emit tch
71emitc ch
72emit tq
73line a
74line part o 0 n
75end
76fn main to int
77squeeze c1 get chars 0
78squeeze c1 get chars 1
79squeeze c2 get chars 2
80squeeze c3 get chars 3
81squeeze c3 get chars 4
82squeeze c3 get chars 5
83ret 0
84end