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

80 lines · 1511 bytes Raw Blame History
1note Rosetta Code task "Determine if a string has all unique characters": https://rosettacode.org/wiki/Determine_if_a_string_has_all_unique_characters
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3om2
4text nl "\n"
5text lq "<<<"
6text rq ">>>"
7text tlen " length "
8text tuni ": all unique\n"
9text tdup ": duplicate '"
10text tat "' at "
11text tand " and "
12text u0 "."
13text u1 "abcABC"
14text u2 "XYZ ZYX"
15text u3 "1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"
16note emit writes every byte of a to stdout; a short write is retried, an error exits 1
17fn emit a view uchar * to void
18o = ulong 0
19while lt o len a bound 4096
20k = write 1 a o sub len a o
21if le k 0
22exit 1
23end
24o = add o ulong k
25end
26end
27note emitu writes n in decimal; 20 digits hold every ulong
28fn emitu n ulong to void
29d = new uchar 20 0
30i = ulong 20
31v = n
32while true bound 20
33i = sub i 1
34put d i uchar add rem v 10 48
35v = div v 10
36if eq v 0
37break
38end
39end
40emit part d i sub 20 i
41end
42note emitc writes one byte
43fn emitc c uchar to void
44b = new uchar 1 0
45put b 0 c
46emit b
47end
48note the first byte (smallest i) that occurs again later, with the place j of its next occurrence
49fn show a view uchar * to void
50emit lq
51emit a
52emit rq
53emit tlen
54emitu len a
55for i ulong len a
56for j ulong sub sub len a i 1
57k = add add i j 1
58if eq get a i get a k
59emit tdup
60emitc get a i
61emit tat
62emitu i
63emit tand
64emitu k
65emit nl
66ret
67end
68end
69end
70emit tuni
71end
72fn main to int
73note the empty string, as a slice of length 0
74show part u0 0 0
75show u0
76show u1
77show u2
78show u3
79ret 0
80end