Unique characters: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 15: Line 15:


=={{header|11l}}==
=={{header|11l}}==
<lang 11l>DefaultDict[Char, Int] d
<syntaxhighlight lang="11l">DefaultDict[Char, Int] d
L(s) [‘133252abcdeeffd’, ‘a6789798st’, ‘yxcdfgxcyz’]
L(s) [‘133252abcdeeffd’, ‘a6789798st’, ‘yxcdfgxcyz’]
L(c) s
L(c) s
Line 22: Line 22:
L(k) sorted(d.keys())
L(k) sorted(d.keys())
I d[k] == 1
I d[k] == 1
print(k, end' ‘’)</lang>
print(k, end' ‘’)</syntaxhighlight>


{{out}}
{{out}}
Line 30: Line 30:


=={{header|8080 Assembly}}==
=={{header|8080 Assembly}}==
<lang 8080asm>puts: equ 9 ; CP/M print syscall
<syntaxhighlight lang="8080asm">puts: equ 9 ; CP/M print syscall
TERM: equ '$' ; CP/M string terminator
TERM: equ '$' ; CP/M string terminator
org 100h
org 100h
Line 86: Line 86:
;;; Memory
;;; Memory
upage: equ ($/256)+1 ; Workspace for 'unique'
upage: equ ($/256)+1 ; Workspace for 'unique'
outbuf: equ (upage+1)*256 ; Output </lang>
outbuf: equ (upage+1)*256 ; Output </syntaxhighlight>
{{out}}
{{out}}
<pre>156bgstz</pre>
<pre>156bgstz</pre>


=={{header|8086 Assembly}}==
=={{header|8086 Assembly}}==
<lang asm> cpu 8086
<syntaxhighlight lang="asm"> cpu 8086
org 100h
org 100h
puts: equ 9 ; MS-DOS syscall to print a string
puts: equ 9 ; MS-DOS syscall to print a string
Line 141: Line 141:
section .bss
section .bss
uniqws: resb 256
uniqws: resb 256
outbuf: resb 256</lang>
outbuf: resb 256</syntaxhighlight>
{{out}}
{{out}}
<pre>156bgstz</pre>
<pre>156bgstz</pre>


=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>DEFINE MAX="128"
<syntaxhighlight lang="action!">DEFINE MAX="128"
CHAR ARRAY counts(MAX)
CHAR ARRAY counts(MAX)


Line 192: Line 192:
FI
FI
OD
OD
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Unique_characters.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Unique_characters.png Screenshot from Atari 8-bit computer]
Line 200: Line 200:


=={{header|Ada}}==
=={{header|Ada}}==
<lang Ada>with Ada.Text_Io;
<syntaxhighlight lang="ada">with Ada.Text_Io;


procedure Unique_Characters is
procedure Unique_Characters is
Line 230: Line 230:
Count ("yxcdfgxcyz");
Count ("yxcdfgxcyz");
Put_Only_Once;
Put_Only_Once;
end Unique_Characters;</lang>
end Unique_Characters;</syntaxhighlight>
{{out}}
{{out}}
<pre>1 5 6 b g s t z</pre>
<pre>1 5 6 b g s t z</pre>
Line 236: Line 236:
=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
Case sensitive. This assumes a small character set (e.g. ASCII where max abs char is 255). Would probably need some work if CHAR is Unicode.
Case sensitive. This assumes a small character set (e.g. ASCII where max abs char is 255). Would probably need some work if CHAR is Unicode.
<lang algol68>BEGIN # find the characters that occur once only in a list of stings #
<syntaxhighlight lang="algol68">BEGIN # find the characters that occur once only in a list of stings #
# returns the characters that occur only once in the elements of s #
# returns the characters that occur only once in the elements of s #
OP UNIQUE = ( []STRING s )STRING:
OP UNIQUE = ( []STRING s )STRING:
Line 257: Line 257:
# task test case #
# task test case #
print( ( UNIQUE []STRING( "133252abcdeeffd", "a6789798st", "yxcdfgxcyz" ), newline ) )
print( ( UNIQUE []STRING( "133252abcdeeffd", "a6789798st", "yxcdfgxcyz" ), newline ) )
END</lang>
END</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 267: Line 267:
The filtering here is case sensitive, the sorting dependent on locale.
The filtering here is case sensitive, the sorting dependent on locale.


<lang applescript>on uniqueCharacters(listOfStrings)
<syntaxhighlight lang="applescript">on uniqueCharacters(listOfStrings)
set astid to AppleScript's text item delimiters
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set AppleScript's text item delimiters to ""
Line 279: Line 279:
return (mutableSet's sortedArrayUsingDescriptors:({sortDescriptor})) as list
return (mutableSet's sortedArrayUsingDescriptors:({sortDescriptor})) as list
end uniqueCharacters</lang>
end uniqueCharacters</syntaxhighlight>


{{output}}
{{output}}
<lang applescript>{"1", "5", "6", "b", "g", "s", "t", "z"}</lang>
<syntaxhighlight lang="applescript">{"1", "5", "6", "b", "g", "s", "t", "z"}</syntaxhighlight>


===Core language only===
===Core language only===
This isn't quite as fast as the ASObjC solution above, but it can be case-insensitive if required. (Simply leave out the 'considering case' statement round the call to the handler). The requirement for AppleScript 2.3.1 is just for the 'use' command which loads the "Heap Sort" script. If "Heap Sort"'s loaded differently or compiled directly into the code, this script will work on systems at least as far back as Mac OS X 10.5 (Leopard) and possibly earlier. Same output as above.
This isn't quite as fast as the ASObjC solution above, but it can be case-insensitive if required. (Simply leave out the 'considering case' statement round the call to the handler). The requirement for AppleScript 2.3.1 is just for the 'use' command which loads the "Heap Sort" script. If "Heap Sort"'s loaded differently or compiled directly into the code, this script will work on systems at least as far back as Mac OS X 10.5 (Leopard) and possibly earlier. Same output as above.


<lang applescript>use AppleScript version "2.3.1" -- OS X 10.9 (Mavericks) or later
<syntaxhighlight lang="applescript">use AppleScript version "2.3.1" -- OS X 10.9 (Mavericks) or later
use sorter : script "Heap Sort" -- <https://www.rosettacode.org/wiki/Sorting_algorithms/Heapsort#AppleScript>
use sorter : script "Heap Sort" -- <https://www.rosettacode.org/wiki/Sorting_algorithms/Heapsort#AppleScript>


Line 321: Line 321:
considering case
considering case
return uniqueCharacters({"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"})
return uniqueCharacters({"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"})
end considering</lang>
end considering</syntaxhighlight>




Line 328: Line 328:
Composing a solution from existing generic primitives, for speed of drafting and refactoring, and for high levels of code reuse.
Composing a solution from existing generic primitives, for speed of drafting and refactoring, and for high levels of code reuse.


<lang applescript>use framework "Foundation"
<syntaxhighlight lang="applescript">use framework "Foundation"




Line 481: Line 481:
((current application's NSArray's arrayWithArray:xs)'s ¬
((current application's NSArray's arrayWithArray:xs)'s ¬
sortedArrayUsingSelector:"compare:") as list
sortedArrayUsingSelector:"compare:") as list
end sort</lang>
end sort</syntaxhighlight>
{{Out}}
{{Out}}
<pre>{"1", "5", "6", "b", "g", "s", "t", "z"}</pre>
<pre>{"1", "5", "6", "b", "g", "s", "t", "z"}</pre>


=={{header|APL}}==
=={{header|APL}}==
<lang APL>uniques ← (⊂∘⍋⌷⊣)∘(∪(/⍨)(1=(≢⊢))⌸)∘∊</lang>
<syntaxhighlight lang="apl">uniques ← (⊂∘⍋⌷⊣)∘(∪(/⍨)(1=(≢⊢))⌸)∘∊</syntaxhighlight>
{{out}}
{{out}}
<pre> uniques '133252abcdeeffd' 'a6789798st' 'yxcdfgxcyz'
<pre> uniques '133252abcdeeffd' 'a6789798st' 'yxcdfgxcyz'
Line 493: Line 493:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>arr: ["133252abcdeeffd" "a6789798st" "yxcdfgxcyz"]
<syntaxhighlight lang="rebol">arr: ["133252abcdeeffd" "a6789798st" "yxcdfgxcyz"]
str: join arr
str: join arr


print sort select split str 'ch -> 1 = size match str ch</lang>
print sort select split str 'ch -> 1 = size match str ch</syntaxhighlight>


{{out}}
{{out}}
Line 503: Line 503:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f UNIQUE_CHARACTERS.AWK
# syntax: GAWK -f UNIQUE_CHARACTERS.AWK
#
#
Line 529: Line 529:
exit(0)
exit(0)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 539: Line 539:


=={{header|BASIC}}==
=={{header|BASIC}}==
<lang basic>10 DEFINT A-Z
<syntaxhighlight lang="basic">10 DEFINT A-Z
20 DIM C(255)
20 DIM C(255)
30 READ A$: IF A$="" GOTO 90
30 READ A$: IF A$="" GOTO 90
Line 554: Line 554:
140 DATA "a6789798st"
140 DATA "a6789798st"
150 DATA "yxcdfgxcyz"
150 DATA "yxcdfgxcyz"
160 DATA ""</lang>
160 DATA ""</syntaxhighlight>
{{out}}
{{out}}
<pre>156bgstz</pre>
<pre>156bgstz</pre>


=={{header|BCPL}}==
=={{header|BCPL}}==
<lang bcpl>get "libhdr"
<syntaxhighlight lang="bcpl">get "libhdr"


let uniques(strings, out) be
let uniques(strings, out) be
Line 587: Line 587:
uniques(strings, out)
uniques(strings, out)
writef("%S*N", out)
writef("%S*N", out)
$)</lang>
$)</syntaxhighlight>
{{out}}
{{out}}
<pre>156bgstz</pre>
<pre>156bgstz</pre>


=={{header|BQN}}==
=={{header|BQN}}==
<lang bqn>Uniq ← (⍷/˜1=/⁼∘⊐)∧∘∾</lang>
<syntaxhighlight lang="bqn">Uniq ← (⍷/˜1=/⁼∘⊐)∧∘∾</syntaxhighlight>


{{out}}
{{out}}
Line 601: Line 601:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
#include <string.h>


Line 633: Line 633:
printf("%s\n", uniques(strings, buf));
printf("%s\n", uniques(strings, buf));
return 0;
return 0;
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>156bgstz</pre>
<pre>156bgstz</pre>


=={{header|C++}}==
=={{header|C++}}==
<lang cpp>#include <iostream>
<syntaxhighlight lang="cpp">#include <iostream>
#include <map>
#include <map>


Line 653: Line 653:
}
}
std::cout << '\n';
std::cout << '\n';
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 662: Line 662:
=={{header|Factor}}==
=={{header|Factor}}==
{{works with|Factor|0.99 build 2074}}
{{works with|Factor|0.99 build 2074}}
<lang factor>USING: io sequences sets.extras sorting ;
<syntaxhighlight lang="factor">USING: io sequences sets.extras sorting ;


{ "133252abcdeeffd" "a6789798st" "yxcdfgxcyz" }
{ "133252abcdeeffd" "a6789798st" "yxcdfgxcyz" }
concat non-repeating natural-sort print</lang>
concat non-repeating natural-sort print</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 673: Line 673:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>Dim As Integer c(255), i, a
<syntaxhighlight lang="freebasic">Dim As Integer c(255), i, a
Dim As String s
Dim As String s
Do
Do
Line 689: Line 689:


Data "133252abcdeeffd", "a6789798st", "yxcdfgxcyz", ""
Data "133252abcdeeffd", "a6789798st", "yxcdfgxcyz", ""
Sleep</lang>
Sleep</syntaxhighlight>
{{out}}
{{out}}
<pre>156bgstz</pre>
<pre>156bgstz</pre>
Line 695: Line 695:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 718: Line 718:
sort.Slice(chars, func(i, j int) bool { return chars[i] < chars[j] })
sort.Slice(chars, func(i, j int) bool { return chars[i] < chars[j] })
fmt.Println(string(chars))
fmt.Println(string(chars))
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 726: Line 726:


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.List (group, sort)
<syntaxhighlight lang="haskell">import Data.List (group, sort)


uniques :: [String] -> String
uniques :: [String] -> String
Line 739: Line 739:
"a6789798st",
"a6789798st",
"yxcdfgxcyz"
"yxcdfgxcyz"
]</lang>
]</syntaxhighlight>
{{Out}}
{{Out}}
<pre>156bgstz</pre>
<pre>156bgstz</pre>
Line 745: Line 745:


Or folding the strings down to a hash of character frequencies:
Or folding the strings down to a hash of character frequencies:
<lang haskell>import qualified Data.Map.Strict as M
<syntaxhighlight lang="haskell">import qualified Data.Map.Strict as M


--------- UNIQUE CHARACTERS FROM A LIST OF STRINGS -------
--------- UNIQUE CHARACTERS FROM A LIST OF STRINGS -------
Line 768: Line 768:
"a6789798st",
"a6789798st",
"yxcdfgxcyz"
"yxcdfgxcyz"
]</lang>
]</syntaxhighlight>
{{Out}}
{{Out}}
<pre>156bgstz</pre>
<pre>156bgstz</pre>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
<lang javascript>(() => {
<syntaxhighlight lang="javascript">(() => {
"use strict";
"use strict";


Line 823: Line 823:
// MAIN ---
// MAIN ---
return JSON.stringify(main());
return JSON.stringify(main());
})();</lang>
})();</syntaxhighlight>
{{Out}}
{{Out}}
<pre>["1","5","6","b","g","s","t","z"]</pre>
<pre>["1","5","6","b","g","s","t","z"]</pre>
Line 830: Line 830:
Or, folding the strings (with Array.reduce) down to a hash of character frequencies:
Or, folding the strings (with Array.reduce) down to a hash of character frequencies:


<lang javascript>(() => {
<syntaxhighlight lang="javascript">(() => {
"use strict";
"use strict";


Line 859: Line 859:


return JSON.stringify(main());
return JSON.stringify(main());
})();</lang>
})();</syntaxhighlight>
{{Out}}
{{Out}}
<pre>["1","5","6","b","s","t","g","z"]</pre>
<pre>["1","5","6","b","s","t","g","z"]</pre>
Line 865: Line 865:
=={{header|J}}==
=={{header|J}}==
The simple approach here is to merge the argument strings and find characters which occur exactly once in that intermediate result:
The simple approach here is to merge the argument strings and find characters which occur exactly once in that intermediate result:
<lang J>uniques=: ~.#~1=#/.~</lang>
<syntaxhighlight lang="j">uniques=: ~.#~1=#/.~</syntaxhighlight>
In other words, <code>~.</code> finds the distinct characters, <code>#/.~</code> finds the corresponding counts of those characters, so <code>1=#/.~</code> is true for the characters which occur exactly once, and <code>#~</code> filters the distinct characters based on those truth values.
In other words, <code>~.</code> finds the distinct characters, <code>#/.~</code> finds the corresponding counts of those characters, so <code>1=#/.~</code> is true for the characters which occur exactly once, and <code>#~</code> filters the distinct characters based on those truth values.
{{out}}
{{out}}
Line 877: Line 877:
'''Works with gojq, the Go implementation of jq'''
'''Works with gojq, the Go implementation of jq'''


The following "bag-of-words" solution is quite efficient as it takes advantage of the fact that jq implements JSON objects as a hash.<lang jq>
The following "bag-of-words" solution is quite efficient as it takes advantage of the fact that jq implements JSON objects as a hash.<syntaxhighlight lang="jq">
# bag of words
# bag of words
def bow(stream):
def bow(stream):
Line 886: Line 886:
def in_one_just_once:
def in_one_just_once:
bow( .[] | explode[] | [.] | implode) | with_entries(select(.value==1)) | keys;
bow( .[] | explode[] | [.] | implode) | with_entries(select(.value==1)) | keys;
</syntaxhighlight>
</lang>
'''The task'''
'''The task'''
<lang jq>["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
<syntaxhighlight lang="jq">["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
| in_one_just_once</lang>
| in_one_just_once</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 896: Line 896:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>list = ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
<syntaxhighlight lang="julia">list = ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]


function is_once_per_all_strings_in(a::Vector{String})
function is_once_per_all_strings_in(a::Vector{String})
Line 905: Line 905:


println(is_once_per_all_strings_in(list))
println(is_once_per_all_strings_in(list))
</lang>{{out}}<pre>
</syntaxhighlight>{{out}}<pre>
['1', '5', '6', 'b', 'g', 's', 't', 'z']
['1', '5', '6', 'b', 'g', 's', 't', 'z']
</pre>
</pre>
One might think that the method above suffers from too many passes through the text with one pass per count, but with a small text length the dictionary lookup takes more time. Compare times for a single pass version:
One might think that the method above suffers from too many passes through the text with one pass per count, but with a small text length the dictionary lookup takes more time. Compare times for a single pass version:


<lang julia>function uniquein(a)
<syntaxhighlight lang="julia">function uniquein(a)
counts = Dict{Char, Int}()
counts = Dict{Char, Int}()
for c in prod(list)
for c in prod(list)
Line 923: Line 923:
@btime is_once_per_all_strings_in(list)
@btime is_once_per_all_strings_in(list)
@btime uniquein(list)
@btime uniquein(list)
</lang>{{out}}<pre>
</syntaxhighlight>{{out}}<pre>
['1', '5', '6', 'b', 'g', 's', 't', 'z']
['1', '5', '6', 'b', 'g', 's', 't', 'z']
1.740 μs (28 allocations: 3.08 KiB)
1.740 μs (28 allocations: 3.08 KiB)
Line 930: Line 930:


This can be rectified (see Phix entry) if we don't save the counts as we go but just exclude entries with duplicates:
This can be rectified (see Phix entry) if we don't save the counts as we go but just exclude entries with duplicates:
<lang julia>function uniquein2(a)
<syntaxhighlight lang="julia">function uniquein2(a)
s = sort(collect(prod(list)))
s = sort(collect(prod(list)))
l = length(s)
l = length(s)
Line 939: Line 939:


@btime uniquein2(list)
@btime uniquein2(list)
</lang>{{out}}<pre>
</syntaxhighlight>{{out}}<pre>
['1', '5', '6', 'b', 'g', 's', 't', 'z']
['1', '5', '6', 'b', 'g', 's', 't', 'z']
1.010 μs (14 allocations: 1.05 KiB)
1.010 μs (14 allocations: 1.05 KiB)
Line 946: Line 946:


=={{header|Lua}}==
=={{header|Lua}}==
<lang Lua>local strings = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}
<syntaxhighlight lang="lua">local strings = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}
unpack = unpack or table.unpack -- compatibility for all Lua versions
unpack = unpack or table.unpack -- compatibility for all Lua versions


Line 970: Line 970:
end
end
table.sort (list)
table.sort (list)
print (unpack (list))</lang>
print (unpack (list))</syntaxhighlight>
{{out}}<pre>1 5 6 b g s t z</pre>
{{out}}<pre>1 5 6 b g s t z</pre>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>Select[Tally[Sort[Characters[StringJoin[{"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}]]]], Last /* EqualTo[1]][[All, 1]]</lang>
<syntaxhighlight lang="mathematica">Select[Tally[Sort[Characters[StringJoin[{"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}]]]], Last /* EqualTo[1]][[All, 1]]</syntaxhighlight>
{{out}}
{{out}}
<pre>{"1", "5", "6", "b", "g", "s", "t", "z"}</pre>
<pre>{"1", "5", "6", "b", "g", "s", "t", "z"}</pre>
Line 981: Line 981:
One solution, but others are possible, for instance concatenating the strings and building the count table from it rather than merging several count tables. And to build the last sequence, we could have used something like <code>sorted(toSeq(charCount.pairs).filterIt(it[1] == 1).mapIt(it[0]))</code>, which is a one liner but less readable and less efficient than our solution using “collect”.
One solution, but others are possible, for instance concatenating the strings and building the count table from it rather than merging several count tables. And to build the last sequence, we could have used something like <code>sorted(toSeq(charCount.pairs).filterIt(it[1] == 1).mapIt(it[0]))</code>, which is a one liner but less readable and less efficient than our solution using “collect”.


<lang Nim>import algorithm, sugar, tables
<syntaxhighlight lang="nim">import algorithm, sugar, tables


var charCount: CountTable[char]
var charCount: CountTable[char]
Line 992: Line 992:
if count == 1: ch
if count == 1: ch


echo sorted(uniqueChars)</lang>
echo sorted(uniqueChars)</syntaxhighlight>


{{out}}
{{out}}
Line 999: Line 999:
=={{header|Pascal}}==
=={{header|Pascal}}==
{{works with|Extended Pascal}}
{{works with|Extended Pascal}}
<lang pascal>program uniqueCharacters(output);
<syntaxhighlight lang="pascal">program uniqueCharacters(output);


type
type
Line 1,055: Line 1,055:
writeLn
writeLn
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>156bgstz</pre>
<pre>156bgstz</pre>
Line 1,061: Line 1,061:
=={{header|Perl}}==
=={{header|Perl}}==
{{trans|Raku}}
{{trans|Raku}}
<lang perl># 20210506 Perl programming solution
<syntaxhighlight lang="perl"># 20210506 Perl programming solution


use strict;
use strict;
Line 1,073: Line 1,073:
"133252abcdeeffd", "a6789798st", "yxcdfgxcyz", "AАΑSäaoö٥🤔👨‍👩‍👧‍👧";
"133252abcdeeffd", "a6789798st", "yxcdfgxcyz", "AАΑSäaoö٥🤔👨‍👩‍👧‍👧";
my $uca = Unicode::Collate->new();
my $uca = Unicode::Collate->new();
print $uca->sort ( grep { $seen{$_} == 1 } keys %seen )</lang>
print $uca->sort ( grep { $seen{$_} == 1 } keys %seen )</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,080: Line 1,080:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">once</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">once</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">l</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
Line 1,090: Line 1,090:
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">set</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)),</span><span style="color: #000000;">once</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">set</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)),</span><span style="color: #000000;">once</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"found %d unique characters: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"found %d unique characters: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #000000;">res</span><span style="color: #0000FF;">})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 1,097: Line 1,097:


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<lang PicoLisp>(de uni (Lst
<syntaxhighlight lang="picolisp">(de uni (Lst
(let R NIL
(let R NIL
(mapc
(mapc
Line 1,115: Line 1,115:
"133252abcdeeffd"
"133252abcdeeffd"
"a6789798st"
"a6789798st"
"yxcdfgxcyz" ) ) )</lang>
"yxcdfgxcyz" ) ) )</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,122: Line 1,122:


=={{header|PL/M}}==
=={{header|PL/M}}==
<lang pli>100H:
<syntaxhighlight lang="pli">100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
Line 1,170: Line 1,170:
CALL PRINT(.BUFFER);
CALL PRINT(.BUFFER);
CALL EXIT;
CALL EXIT;
EOF</lang>
EOF</syntaxhighlight>
{{out}}
{{out}}
<pre>156BGSTZ</pre>
<pre>156BGSTZ</pre>


=={{header|Python}}==
=={{header|Python}}==
<lang python>'''Unique characters'''
<syntaxhighlight lang="python">'''Unique characters'''


from itertools import chain, groupby
from itertools import chain, groupby
Line 1,209: Line 1,209:
# MAIN ---
# MAIN ---
if __name__ == '__main__':
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>
{{Out}}
{{Out}}
<pre>['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>
<pre>['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>


Or reducing the given strings down to a hash of character frequencies:
Or reducing the given strings down to a hash of character frequencies:
<lang python>'''Unique characters'''
<syntaxhighlight lang="python">'''Unique characters'''


from functools import reduce
from functools import reduce
Line 1,255: Line 1,255:
# MAIN ---
# MAIN ---
if __name__ == '__main__':
if __name__ == '__main__':
main()</lang>
main()</syntaxhighlight>
{{Out}}
{{Out}}
<pre>['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>
<pre>['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>
Line 1,262: Line 1,262:
One has to wonder where the digits 0 through 9 come in the alphabet... 🤔 For that matter, What alphabet should they be in order of? Most of these entries seem to presuppose ASCII order but that isn't specified anywhere. What to do with characters outside of ASCII (or Latin-1)? Unicode ordinal order? Or maybe DUCET Unicode collation order? It's all very vague.
One has to wonder where the digits 0 through 9 come in the alphabet... 🤔 For that matter, What alphabet should they be in order of? Most of these entries seem to presuppose ASCII order but that isn't specified anywhere. What to do with characters outside of ASCII (or Latin-1)? Unicode ordinal order? Or maybe DUCET Unicode collation order? It's all very vague.


<lang perl6>my @list = <133252abcdeeffd a6789798st yxcdfgxcyz>;
<syntaxhighlight lang="raku" line>my @list = <133252abcdeeffd a6789798st yxcdfgxcyz>;


for @list, (@list, 'AАΑSäaoö٥🤔👨‍👩‍👧‍👧') {
for @list, (@list, 'AАΑSäaoö٥🤔👨‍👩‍👧‍👧') {
Line 1,269: Line 1,269:
"\n (DUCET) Unicode collation order: ",
"\n (DUCET) Unicode collation order: ",
.map( *.comb ).Bag.grep( *.value == 1 )».key.collate.join, "\n";
.map( *.comb ).Bag.grep( *.value == 1 )».key.collate.join, "\n";
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>133252abcdeeffd a6789798st yxcdfgxcyz
<pre>133252abcdeeffd a6789798st yxcdfgxcyz
Line 1,289: Line 1,289:


On an &nbsp;'''EBCDIC'''&nbsp; machine, &nbsp; the lowercase letters and the uppercase letters &nbsp; aren't &nbsp; contiguous.
On an &nbsp;'''EBCDIC'''&nbsp; machine, &nbsp; the lowercase letters and the uppercase letters &nbsp; aren't &nbsp; contiguous.
<lang rexx>/*REXX pgm finds and shows characters that are unique to only one string and once only.*/
<syntaxhighlight lang="rexx">/*REXX pgm finds and shows characters that are unique to only one string and once only.*/
parse arg $ /*obtain optional arguments from the CL*/
parse arg $ /*obtain optional arguments from the CL*/
if $='' | $="," then $= '133252abcdeeffd' "a6789798st" 'yxcdfgxcyz' /*use defaults.*/
if $='' | $="," then $= '133252abcdeeffd' "a6789798st" 'yxcdfgxcyz' /*use defaults.*/
Line 1,307: Line 1,307:
say 'unique characters are: ' @ /*display the unique characters found. */
say 'unique characters are: ' @ /*display the unique characters found. */
say
say
say 'Found ' L " unique characters." /*display the # of unique chars found. */</lang>
say 'Found ' L " unique characters." /*display the # of unique chars found. */</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>
Line 1,316: Line 1,316:


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
see "working..." + nl
see "working..." + nl
see "Unique characters are:" + nl
see "Unique characters are:" + nl
Line 1,349: Line 1,349:
end
end
return sum
return sum
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,360: Line 1,360:


=={{header|Vlang}}==
=={{header|Vlang}}==
<lang vlang>fn main() {
<syntaxhighlight lang="vlang">fn main() {
strings := ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
strings := ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
mut m := map[rune]int{}
mut m := map[rune]int{}
Line 1,384: Line 1,384:
})
})
println(chars.string())
println(chars.string())
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 1,394: Line 1,394:
{{libheader|Wren-seq}}
{{libheader|Wren-seq}}
{{libheader|Wren-sort}}
{{libheader|Wren-sort}}
<lang ecmascript>import "/seq" for Lst
<syntaxhighlight lang="ecmascript">import "/seq" for Lst
import "/sort" for Sort
import "/sort" for Sort


Line 1,402: Line 1,402:
Sort.insertion(uniqueChars)
Sort.insertion(uniqueChars)
System.print("Found %(uniqueChars.count) unique character(s), namely:")
System.print("Found %(uniqueChars.count) unique character(s), namely:")
System.print(uniqueChars.join(" "))</lang>
System.print(uniqueChars.join(" "))</syntaxhighlight>


{{out}}
{{out}}
Line 1,413: Line 1,413:
=={{header|Yabasic}}==
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
{{trans|FreeBASIC}}
<lang yabasic>dim c(255)
<syntaxhighlight lang="yabasic">dim c(255)
data "133252abcdeeffd", "a6789798st", "yxcdfgxcyz", ""
data "133252abcdeeffd", "a6789798st", "yxcdfgxcyz", ""
repeat
repeat
Line 1,427: Line 1,427:
next i
next i
print s$
print s$
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,435: Line 1,435:


=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>int List, I, N, C;
<syntaxhighlight lang="xpl0">int List, I, N, C;
char Tbl(128), Str;
char Tbl(128), Str;
string 0;
string 0;
Line 1,451: Line 1,451:
for I:= 0 to 127 do
for I:= 0 to 127 do
if Tbl(I) = 1 then ChOut(0, I);
if Tbl(I) = 1 then ChOut(0, I);
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}