Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/omega-rosetta/blob/main/drafts/rosettacode/determine-if-a-string-has-all-the-same-characters.wiki
# omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
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}}
3 Omega has no imports, so the small output helpers (emit and friends) are part of the program.
4
5 om2
6 text nl "\n"
7 text lq "<<<"
8 text rq ">>>"
9 text tlen " length "
10 text tsame ": all the same\n"
11 text tdiff ": first different '"
12 text tat "' at "
13 text u0 " "
14 text u1 "2"
15 text u2 "333"
16 text u3 ".55"
17 text u4 "tttTTT"
18 text u5 "4444 444k"
19 note emit writes every byte of a to stdout; a short write is retried, an error exits 1
20 fn emit a view uchar * to void
21 o = ulong 0
22 while lt o len a bound 4096
23 k = write 1 a o sub len a o
24 if le k 0
25 exit 1
26 end
27 o = add o ulong k
28 end
29 end
30 note emitu writes n in decimal; 20 digits hold every ulong
31 fn emitu n ulong to void
32 d = new uchar 20 0
33 i = ulong 20
34 v = n
35 while true bound 20
36 i = sub i 1
37 put d i uchar add rem v 10 48
38 v = div v 10
39 if eq v 0
40 break
41 end
42 end
43 emit part d i sub 20 i
44 end
45 note emitc writes one byte
46 fn emitc c uchar to void
47 b = new uchar 1 0
48 put b 0 c
49 emit b
50 end
51 fn show a view uchar * to void
52 emit lq
53 emit a
54 emit rq
55 emit tlen
56 emitu len a
57 for i ulong len a
58 if ne get a i get a 0
59 emit tdiff
60 emitc get a i
61 emit tat
62 emitu i
63 emit nl
64 ret
65 end
66 end
67 emit tsame
68 end
69 fn main to int
70 note the empty string, as a slice of length 0
71 show part u0 0 0
72 show u0
73 show u1
74 show u2
75 show u3
76 show u4
77 show u5
78 ret 0
79 end
80
81 {{out}}
82
83 <<<>>> length 0: all the same
84 <<< >>> length 3: all the same
85 <<<2>>> length 1: all the same
86 <<<333>>> length 3: all the same
87 <<<.55>>> length 3: first different '5' at 1
88 <<<tttTTT>>> length 6: first different 'T' at 3
89 <<<4444 444k>>> length 9: first different ' ' at 4
90