interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / drafts / rosettacode / determine-if-a-string-is-squeezable.wiki

108 lines · 3071 bytes Raw Blame History
1=={{header|Omegese}}==
2{{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}}
3Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program.
4<syntaxhighlight lang="text">
5om2
6text nl "\n"
7text lq "<<<"
8text rq ">>>"
9text tlen " length "
10text tch "squeeze '"
11text tq "'\n"
12text c0 "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln "
13text c1 "..1111111111111111111111111111111111111111111111111111111111111117777888"
14text c2 "I never give 'em hell, I just tell the truth, and they think it's hell. "
15text c3 " --- Harry S Truman "
16text chars "-7. -r"
17note emit writes every byte of a to stdout; a short write is retried, an error exits 1
18fn emit a view uchar * to void
19o = ulong 0
20while lt o len a bound 4096
21k = write 1 a o sub len a o
22if le k 0
23exit 1
24end
25o = add o ulong k
26end
27end
28note emitu writes n in decimal; 20 digits hold every ulong
29fn emitu n ulong to void
30d = new uchar 20 0
31i = ulong 20
32v = n
33while true bound 20
34i = sub i 1
35put d i uchar add rem v 10 48
36v = div v 10
37if eq v 0
38break
39end
40end
41emit part d i sub 20 i
42end
43note emitc writes one byte
44fn emitc c uchar to void
45b = new uchar 1 0
46put b 0 c
47emit b
48end
49fn line a view uchar * to void
50emit lq
51emit a
52emit rq
53emit tlen
54emitu len a
55emit nl
56end
57note squeeze drops a byte equal to ch when the byte before it is also ch
58fn squeeze a view uchar * ch uchar to void
59o = new uchar 256 0
60n = ulong 0
61for i ulong len a
62c = get a i
63k = true
64if and gt i 0 eq c ch
65k = ne get a sub i 1 ch
66end
67if k
68put o n c
69n = add n 1
70end
71end
72emit tch
73emitc ch
74emit tq
75line a
76line part o 0 n
77end
78fn main to int
79squeeze c1 get chars 0
80squeeze c1 get chars 1
81squeeze c2 get chars 2
82squeeze c3 get chars 3
83squeeze c3 get chars 4
84squeeze c3 get chars 5
85ret 0
86end
87</syntaxhighlight>
88{{out}}
89<pre>
90squeeze '-'
91&lt;&lt;&lt;..1111111111111111111111111111111111111111111111111111111111111117777888>>> length 72
92&lt;&lt;&lt;..1111111111111111111111111111111111111111111111111111111111111117777888>>> length 72
93squeeze '7'
94&lt;&lt;&lt;..1111111111111111111111111111111111111111111111111111111111111117777888>>> length 72
95&lt;&lt;&lt;..1111111111111111111111111111111111111111111111111111111111111117888>>> length 69
96squeeze '.'
97&lt;&lt;&lt;I never give 'em hell, I just tell the truth, and they think it's hell. >>> length 72
98&lt;&lt;&lt;I never give 'em hell, I just tell the truth, and they think it's hell. >>> length 72
99squeeze ' '
100&lt;&lt;&lt; --- Harry S Truman >>> length 72
101&lt;&lt;&lt; --- Harry S Truman >>> length 20
102squeeze '-'
103&lt;&lt;&lt; --- Harry S Truman >>> length 72
104&lt;&lt;&lt; - Harry S Truman >>> length 70
105squeeze 'r'
106&lt;&lt;&lt; --- Harry S Truman >>> length 72
107&lt;&lt;&lt; --- Hary S Truman >>> length 71
108</pre>