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-has-all-the-same-characters.wiki

90 lines · 1750 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 tsame ": all the same\n"
11text tdiff ": first different '"
12text tat "' at "
13text u0 " "
14text u1 "2"
15text u2 "333"
16text u3 ".55"
17text u4 "tttTTT"
18text u5 "4444 444k"
19note emit writes every byte of a to stdout; a short write is retried, an error exits 1
20fn emit a view uchar * to void
21o = ulong 0
22while lt o len a bound 4096
23k = write 1 a o sub len a o
24if le k 0
25exit 1
26end
27o = add o ulong k
28end
29end
30note emitu writes n in decimal; 20 digits hold every ulong
31fn emitu n ulong to void
32d = new uchar 20 0
33i = ulong 20
34v = n
35while true bound 20
36i = sub i 1
37put d i uchar add rem v 10 48
38v = div v 10
39if eq v 0
40break
41end
42end
43emit part d i sub 20 i
44end
45note emitc writes one byte
46fn emitc c uchar to void
47b = new uchar 1 0
48put b 0 c
49emit b
50end
51fn show a view uchar * to void
52emit lq
53emit a
54emit rq
55emit tlen
56emitu len a
57for i ulong len a
58if ne get a i get a 0
59emit tdiff
60emitc get a i
61emit tat
62emitu i
63emit nl
64ret
65end
66end
67emit tsame
68end
69fn main to int
70note the empty string, as a slice of length 0
71show part u0 0 0
72show u0
73show u1
74show u2
75show u3
76show u4
77show u5
78ret 0
79end
80</syntaxhighlight>
81{{out}}
82<pre>
83&lt;&lt;&lt;>>> length 0: all the same
84&lt;&lt;&lt; >>> length 3: all the same
85&lt;&lt;&lt;2>>> length 1: all the same
86&lt;&lt;&lt;333>>> length 3: all the same
87&lt;&lt;&lt;.55>>> length 3: first different '5' at 1
88&lt;&lt;&lt;tttTTT>>> length 6: first different 'T' at 3
89&lt;&lt;&lt;4444 444k>>> length 9: first different ' ' at 4
90</pre>