Determine if a string has all unique characters: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
|||
Line 35: | Line 35: | ||
{{Template:Strings}} |
{{Template:Strings}} |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
|||
{{trans|Kotlin}} |
|||
<lang 11l>F processString(input) |
|||
[Char = Int] charMap |
|||
V dup = Char("\0") |
|||
V index = 0 |
|||
V pos1 = -1 |
|||
V pos2 = -1 |
|||
L(key) input |
|||
index++ |
|||
I key C charMap |
|||
dup = key |
|||
pos1 = charMap[key] |
|||
pos2 = index |
|||
L.break |
|||
charMap[key] = index |
|||
V unique = I dup == Char("\0") {‘yes’} E ‘no’ |
|||
V diff = I dup == Char("\0") {‘’} E ‘'’dup‘'’ |
|||
V hexs = I dup == Char("\0") {‘’} E hex(dup.code) |
|||
V position = I dup == Char("\0") {‘’} E pos1‘ ’pos2 |
|||
print(‘#<40 #<6 #<10 #<8 #<3 #<5’.format(input, input.len, unique, diff, hexs, position)) |
|||
print(‘#<40 #2 #10 #8 #. #.’.format(‘String’, ‘Length’, ‘All Unique’, ‘1st Diff’, ‘Hex’, ‘Positions’)) |
|||
print(‘#<40 #2 #10 #8 #. #.’.format(‘------------------------’, ‘------’, ‘----------’, ‘--------’, ‘---’, ‘---------’)) |
|||
L(s) [‘’, ‘.’, ‘abcABC’, ‘XYZ ZYX’, ‘1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ’] |
|||
processString(s)</lang> |
|||
{{out}} |
|||
<pre> |
|||
String Length All Unique 1st Diff Hex Positions |
|||
------------------------ ------ ---------- -------- --- --------- |
|||
0 yes |
|||
. 1 yes |
|||
abcABC 6 yes |
|||
XYZ ZYX 7 no 'Z' 5A 3 5 |
|||
1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ 36 no '0' 30 10 25 |
|||
</pre> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |