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

julia example
(→‎{{header|Perl}}: works better with Unicode combining characters)
(julia example)
Line 160:
'🐡' (0x1f421) is duplicated at positions 3 and 8.
</pre>
 
=={{header|Julia}}==
<lang julia>arr(s) = [c for c in s]
alldup(a) = filter(x -> length(x) > 1, [findall(x -> x == a[i], a) for i in 1:length(a)])
firstduplicate(s) = (a = arr(s); d = alldup(a); isempty(d) ? nothing : first(d))
 
function testfunction(strings)
println("String | Length | All Unique | First Duplicate | Positions\n" *
"-------------------------------------------------------------------------------------")
for s in strings
n = firstduplicate(s)
a = arr(s)
println(rpad(s, 38), rpad(length(s), 11), n == nothing ? "yes" :
rpad("no $(a[n[1]])", 26) * rpad(n[1], 4) * "$(n[2])")
end
end
 
testfunction([
"",
".",
"abcABC",
"XYZ ZYX",
"1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ",
"hétérogénéité",
"🎆🎃🎇🎈",
"😍😀🙌💃😍🙌",
"🐠🐟🐡🦈🐬🐳🐋🐡",
])
</lang>{{out}}
<pre>
String | Length | All Unique | First Duplicate | Positions
-------------------------------------------------------------------------------------
0 yes
. 1 yes
abcABC 6 yes
XYZ ZYX 7 no X 1 7
1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ 36 no 0 10 25
hétérogénéité 13 no é 2 4
🎆🎃🎇🎈 4 yes
😍😀🙌💃😍🙌 6 no 😍 1 5
🐠🐟🐡🦈🐬🐳🐋🐡 8 no 🐡 3 8
</pre>
 
 
=={{header|Perl}}==
4,105

edits