Determine if a string has all unique characters: Difference between revisions

Content added Content deleted
(Add OCaml)
(add bqn)
Line 774: Line 774:
|----------------------------------------|--------|------------|----------|-----|-----------|
|----------------------------------------|--------|------------|----------|-----|-----------|
</pre>
</pre>

=={{header|BQN}}==

O(n^2) method used for finding indices.

Hex function and loop similar to [[Determine if a string has all the same characters#BQN|Determine if a string has all the same characters]]


<lang bqn>Check←=⌜˜
Hex←⊏⟜(∾"0A"+⟜↕¨10‿26)16{⌽𝕗|⌊∘÷⟜𝕗⍟(↕1+·⌊𝕗⋆⁼1⌈⊢)}
{
𝕊 str:
r←Check str
•Out {
∧´1=+´˘r ? "All characters are unique" ;
i←/⊏(1<+´˘r)/r
ch←(⊑i)⊑str
"'"∾ch∾"' (hex: "∾(Hex ch-@)∾", indices: "∾(•Fmt i)∾") duplicated in string '"∾str∾"'"
}
}¨⟨
""
"."
"abcABC"
"XYZ ZYX"
"1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"
⟩</lang><lang>All characters are unique
All characters are unique
All characters are unique
'X' (hex: 58, indices: ⟨ 0 7 ⟩) duplicated in string 'XYZ ZYX'
'0' (hex: 30, indices: ⟨ 9 24 ⟩) duplicated in string '1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ'</lang>


=={{header|C}}==
=={{header|C}}==