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-has-all-the-same-characters / determine-if-a-string-has-all-the-same-characters.om

77 lines · 1354 bytes Raw Blame History
1note Rosetta Code task "Determine if a string has all the same characters": https://rosettacode.org/wiki/Determine_if_a_string_has_all_the_same_characters
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text lq "<<<"
6text rq ">>>"
7text tlen " length "
8text tsame ": all the same\n"
9text tdiff ": first different '"
10text tat "' at "
11text u0 " "
12text u1 "2"
13text u2 "333"
14text u3 ".55"
15text u4 "tttTTT"
16text u5 "4444 444k"
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 show a view uchar * to void
50emit lq
51emit a
52emit rq
53emit tlen
54emitu len a
55for i ulong len a
56if ne get a i get a 0
57emit tdiff
58emitc get a i
59emit tat
60emitu i
61emit nl
62ret
63end
64end
65emit tsame
66end
67fn main to int
68note the empty string, as a slice of length 0
69show part u0 0 0
70show u0
71show u1
72show u2
73show u3
74show u4
75show u5
76ret 0
77end