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

no edit summary
m (C++ solution made slightly neater)
No edit summary
Line 1,477:
🐠🐟🐡🦈🐬🐳🐋🐡 8 no 🐡 (1f421) 3 8
</pre>
 
=={{header|Nanoquery}}==
<lang nanoquery>def analyze(s)
s = str(s)
println "Examining [" + s + "] which has a length of " + str(len(s)) + ":"
 
if len(s) < 2
println "\tAll characters in the string are unique."
return
end
 
seen = list()
for i in range(0, len(s) - 2)
if s[i] in seen
println "\tNot all characters in the string are unique."
println "\t'" + s[i] + "' " + format("(0x%x)", ord(s[i])) +\
" is duplicated at positions " + str(i + 1) + " and " +\
str(s.indexOf(s[i]) + 1)
return
end
seen.append(s[i])
end
 
println "\tAll characters in the string are unique."
end
 
tests = {"", ".", "abcABC", "XYZ ZYX", "1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"}
for s in tests
analyze(s)
end</lang>
{{out}}
<pre>Examining [] which has a length of 0:
All characters in the string are unique.
Examining [.] which has a length of 1:
All characters in the string are unique.
Examining [abcABC] which has a length of 6:
All characters in the string are unique.
Examining [XYZ ZYX] which has a length of 7:
Not all characters in the string are unique.
'Z' (0x5a) is duplicated at positions 5 and 3
Examining [1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ] which has a length of 36:
Not all characters in the string are unique.
'0' (0x30) is duplicated at positions 25 and 10</pre>
 
=={{header|Perl}}==
Anonymous user