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-unique-characters.wiki

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