Unique characters: Difference between revisions

Add two StandardML versions
(Add two StandardML versions)
 
(47 intermediate revisions by 22 users not shown)
Line 13:
{{Template:Strings}}
<br><br>
 
=={{header|11l}}==
<syntaxhighlight lang="11l">DefaultDict[Char, Int] d
L(s) [‘133252abcdeeffd’, ‘a6789798st’, ‘yxcdfgxcyz’]
L(c) s
d[c]++
 
L(k) sorted(d.keys())
I d[k] == 1
print(k, end' ‘’)</syntaxhighlight>
 
{{out}}
<pre>
156bgstz
</pre>
 
=={{header|8080 Assembly}}==
<langsyntaxhighlight lang="8080asm">puts: equ 9 ; CP/M print syscall
TERM: equ '$' ; CP/M string terminator
org 100h
Line 71 ⟶ 86:
;;; Memory
upage: equ ($/256)+1 ; Workspace for 'unique'
outbuf: equ (upage+1)*256 ; Output </langsyntaxhighlight>
{{out}}
<pre>156bgstz</pre>
 
 
=={{header|8086 Assembly}}==
<langsyntaxhighlight lang="asm"> cpu 8086
org 100h
puts: equ 9 ; MS-DOS syscall to print a string
Line 127 ⟶ 141:
section .bss
uniqws: resb 256
outbuf: resb 256</langsyntaxhighlight>
{{out}}
<pre>156bgstz</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">DEFINE MAX="128"
CHAR ARRAY counts(MAX)
 
BYTE FUNC GetCount(CHAR ARRAY s CHAR c)
BYTE count,i
 
count=0
FOR i=1 TO s(0)
DO
IF s(i)=c THEN
count==+1
FI
OD
RETURN (count)
 
PROC UpdateCounts(CHAR ARRAY s)
BYTE i,c
 
FOR i=1 TO s(0)
DO
c=s(i)
counts(c)==+GetCount(s,c)
OD
RETURN
 
PROC Main()
DEFINE PTR="CARD"
DEFINE CNT="3"
PTR ARRAY l(CNT)
INT i
 
l(0)="133252abcdeeffd"
l(1)="a6789798st"
l(2)="yxcdfgxcyz"
 
SetBlock(counts,MAX,0)
FOR i=0 TO CNT-1
DO
UpdateCounts(l(i))
OD
FOR i=0 TO MAX-1
DO
IF counts(i)=1 THEN
Put(i) Put(32)
FI
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Unique_characters.png Screenshot from Atari 8-bit computer]
<pre>
1 5 6 b g s t z
</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_Io;
 
procedure Unique_Characters is
 
List : array (Character) of Natural := (others => 0);
 
procedure Count (Item : String) is
begin
for C of Item loop
List (C) := List (C) + 1;
end loop;
end Count;
 
procedure Put_Only_Once is
use Ada.Text_Io;
begin
for C in List'Range loop
if List (C) = 1 then
Put (C);
Put (' ');
end if;
end loop;
New_Line;
end Put_Only_Once;
 
begin
Count ("133252abcdeeffd");
Count ("a6789798st");
Count ("yxcdfgxcyz");
Put_Only_Once;
end Unique_Characters;</syntaxhighlight>
{{out}}
<pre>1 5 6 b g s t z</pre>
 
=={{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.
<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 #
OP UNIQUE = ( []STRING s )STRING:
BEGIN
[ 0 : max abs char ]INT counts; # counts of used characters #
FOR i FROM LWB counts TO UPB counts DO counts[ i ] := 0 OD;
# count the occurances of the characters in the elements of s #
FOR i FROM LWB s TO UPB s DO
FOR j FROM LWB s[ i ] TO UPB s[ i ] DO
counts[ ABS s[ i ][ j ] ] +:= 1
OD
OD;
# construct a string of the characters that occur only once #
STRING result := "";
FOR i FROM LWB counts TO UPB counts DO
IF counts[ i ] = 1 THEN result +:= REPR i FI
OD;
result
END; # UNIQUE #
# task test case #
print( ( UNIQUE []STRING( "133252abcdeeffd", "a6789798st", "yxcdfgxcyz" ), newline ) )
END</syntaxhighlight>
{{out}}
<pre>
156bgstz
</pre>
 
=={{header|AppleScript}}==
Line 135 ⟶ 267:
The filtering here is case sensitive, the sorting dependent on locale.
 
<langsyntaxhighlight lang="applescript">on uniqueCharacters(listOfStrings)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
Line 147 ⟶ 279:
return (mutableSet's sortedArrayUsingDescriptors:({sortDescriptor})) as list
end uniqueCharacters</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">{"1", "5", "6", "b", "g", "s", "t", "z"}</langsyntaxhighlight>
 
===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.
 
<langsyntaxhighlight 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>
 
Line 189 ⟶ 321:
considering case
return uniqueCharacters({"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"})
end considering</langsyntaxhighlight>
 
 
Line 196 ⟶ 328:
Composing a solution from existing generic primitives, for speed of drafting and refactoring, and for high levels of code reuse.
 
<langsyntaxhighlight lang="applescript">use framework "Foundation"
 
 
Line 349 ⟶ 481:
((current application's NSArray's arrayWithArray:xs)'s ¬
sortedArrayUsingSelector:"compare:") as list
end sort</langsyntaxhighlight>
{{Out}}
<pre>{"1", "5", "6", "b", "g", "s", "t", "z"}</pre>
 
=={{header|APL}}==
<langsyntaxhighlight APLlang="apl">uniques ← (⊂∘⍋⌷⊣)∘(∪(/⍨)(1=(≢⊢))⌸)∘∊</langsyntaxhighlight>
{{out}}
<pre> uniques '133252abcdeeffd' 'a6789798st' 'yxcdfgxcyz'
Line 361 ⟶ 493:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">arr: ["133252abcdeeffd" "a6789798st" "yxcdfgxcyz"]
str: join arr
 
print sort select split str 'ch -> 1 = size match str ch</langsyntaxhighlight>
 
{{out}}
Line 371 ⟶ 503:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f UNIQUE_CHARACTERS.AWK
#
Line 397 ⟶ 529:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 407 ⟶ 539:
 
=={{header|BASIC}}==
<langsyntaxhighlight lang="basic">10 DEFINT A-Z
20 DIM C(255)
30 READ A$: IF A$="" GOTO 90
Line 422 ⟶ 554:
140 DATA "a6789798st"
150 DATA "yxcdfgxcyz"
160 DATA ""</langsyntaxhighlight>
{{out}}
<pre>156bgstz</pre>
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let uniques(strings, out) be
Line 455 ⟶ 587:
uniques(strings, out)
writef("%S*N", out)
$)</langsyntaxhighlight>
{{out}}
<pre>156bgstz</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">Uniq ← (⍷/˜1=/⁼∘⊐)∧∘∾</syntaxhighlight>
 
{{out}}
<pre>
Uniq "133252abcdeeffd"‿"a6789798st"‿"yxcdfgxcyz"
"156bgstz"
</pre>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <string.h>
 
Line 492 ⟶ 633:
printf("%s\n", uniques(strings, buf));
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>156bgstz</pre>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <map>
 
Line 512 ⟶ 653:
}
std::cout << '\n';
}</langsyntaxhighlight>
 
{{out}}
Line 518 ⟶ 659:
156bgstz
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
var SA: array [0..2] of string = ('133252abcdeeffd', 'a6789798st', 'yxcdfgxcyz');
 
function CharsAppearingOnce(S: string): string;
{Return all character that only occur once}
var SL: TStringList;
var I,Inx: integer;
begin
SL:=TStringList.Create;
try
{Store each character and store a count}
{of the number of occurances in the object}
for I:=1 to Length(S) do
begin
{Check to see if letter is already in list}
Inx:=SL.IndexOf(S[I]);
{Increment the count if it is, otherwise store it}
if Inx>=0 then SL.Objects[Inx]:=Pointer(Integer(SL.Objects[Inx])+1)
else SL.AddObject(S[I],Pointer(1));
end;
{Sort the list}
SL.Sort;
{Now return letters with a count of one}
Result:='';
for I:=0 to SL.Count-1 do
if integer(SL.Objects[I])<2 then Result:=Result+SL[I];
finally SL.Free; end;
end;
 
procedure ShowUniqueChars(Memo: TMemo);
var I: integer;
var S: string;
begin
{Concatonate all strings}
S:='';
for I:=0 to High(SA) do S:=S+SA[I];
{Get all characters that appear once}
S:=CharsAppearingOnce(S);
Memo.Lines.Add(S);
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
156bgstz
 
Elapsed Time: 0.959 ms.
 
</pre>
 
 
=={{header|Factor}}==
{{works with|Factor|0.99 build 2074}}
<langsyntaxhighlight lang="factor">USING: io sequences sets.extras sorting ;
 
{ "133252abcdeeffd" "a6789798st" "yxcdfgxcyz" }
concat non-repeating natural-sort print</langsyntaxhighlight>
{{out}}
<pre>
156bgstz
</pre>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">Dim As Integer c(255), i, a
Dim As String s
Do
Read s
For i = 1 To Len(s)
a = Asc(Mid(s,i,1))
c(a) += 1
Next i
Loop Until s = ""
 
For i = 1 To 255
If c(i) = 1 Then s &= Chr(i)
Next i
Print s
 
Data "133252abcdeeffd", "a6789798st", "yxcdfgxcyz", ""
Sleep</syntaxhighlight>
{{out}}
<pre>156bgstz</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">window 1, @"Unique characters"
 
void local fn DoIt
CountedSetRef set = fn CountedSetWithCapacity(0)
CFArrayRef array = @[@"133252abcdeeffd",@"a6789798st",@"yxcdfgxcyz"]
CFStringRef string, chr
long index
CFMutableArrayRef mutArray = fn MutableArrayWithCapacity(0)
for string in array
for index = 0 to len(string) - 1
CountedSetAddObject( set, mid(string,index,1) )
next
next
for chr in set
if ( fn CountedSetCountForObject( set, chr ) == 1 )
MutableArrayAddObject( mutArray, chr )
end if
next
MutableArraySortUsingSelector( mutArray, @"compare:" )
print fn ArrayComponentsJoinedByString( mutArray, @"" )
end fn
 
fn DoIt
 
HandleEvents</syntaxhighlight>
{{out}}
<pre>156bgstz</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 554 ⟶ 808:
sort.Slice(chars, func(i, j int) bool { return chars[i] < chars[j] })
fmt.Println(string(chars))
}</langsyntaxhighlight>
 
{{out}}
Line 562 ⟶ 816:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.List (group, sort)
 
uniques :: [String] -> String
Line 575 ⟶ 829:
"a6789798st",
"yxcdfgxcyz"
]</langsyntaxhighlight>
{{Out}}
<pre>156bgstz</pre>
 
 
Or folding the strings down to a hash of character frequencies:
<syntaxhighlight lang="haskell">import qualified Data.Map.Strict as M
 
--------- UNIQUE CHARACTERS FROM A LIST OF STRINGS -------
 
uniqueChars :: [String] -> String
uniqueChars =
M.keys . M.filter (1 ==)
. foldr (M.unionWith (+) . charCounts) M.empty
 
charCounts :: String -> M.Map Char Int
charCounts =
foldr
(flip (M.insertWith (+)) 1)
M.empty
 
--------------------------- TEST -------------------------
main :: IO ()
main =
putStrLn $
uniqueChars
[ "133252abcdeeffd",
"a6789798st",
"yxcdfgxcyz"
]</syntaxhighlight>
{{Out}}
<pre>156bgstz</pre>
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">(() => {
"use strict";
 
// ---------------- UNIQUE CHARACTERS ----------------
 
// uniques :: [String] -> [Char]
const uniques = xs =>
group(
xs.flatMap(x => [...x])
.sort()
)
.flatMap(
x => 1 === x.length ? (
x
) : []
);
 
// ---------------------- TEST -----------------------
// main :: IO ()
const main = () =>
uniques([
"133252abcdeeffd",
"a6789798st",
"yxcdfgxcyz"
]);
 
 
// --------------------- GENERIC ---------------------
 
// group :: Eq a => [a] -> [[a]]
const group = xs => {
// A list of lists, each containing only equal elements,
// such that the concatenation of these lists is xs.
const go = ys =>
0 < ys.length ? (() => {
const
h = ys[0],
i = ys.findIndex(y => h !== y);
 
return i !== -1 ? (
[ys.slice(0, i)].concat(go(ys.slice(i)))
) : [ys];
})() : [];
 
return go(xs);
};
 
 
// MAIN ---
return JSON.stringify(main());
})();</syntaxhighlight>
{{Out}}
<pre>["1","5","6","b","g","s","t","z"]</pre>
 
 
Or, folding the strings (with Array.reduce) down to a hash of character frequencies:
 
<syntaxhighlight lang="javascript">(() => {
"use strict";
 
// uniqueChars :: [String] -> [Char]
const uniqueChars = ws =>
Object.entries(
ws.reduce(
(dict, w) => [...w].reduce(
(a, c) => Object.assign({}, a, {
[c]: 1 + (a[c] || 0)
}),
dict
), {}
)
)
.flatMap(
([k, v]) => 1 === v ? (
[k]
) : []
);
 
// ---------------------- TEST -----------------------
const main = () =>
uniqueChars([
"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"
]);
 
 
return JSON.stringify(main());
})();</syntaxhighlight>
{{Out}}
<pre>["1","5","6","b","s","t","g","z"]</pre>
 
=={{header|J}}==
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=+/"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.
{{out}}
<pre> uniques ;'133252abcdeeffd';'a6789798st';'yxcdfgxcyz'
156bgstz</pre>
 
Here, <code>;</code> as a separator between quoted strings builds a list of the strings, and <code>;</code> as a prefix of that list merges the contents of the strings of that list into a single string. We could just as easily have formed a single string, but that's not what the task asked for. (Since <code>uniques</code> is a verb (aka a "function"), it's not a list element in this context.)
 
=={{header|jq}}==
Line 589 ⟶ 967:
'''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.<langsyntaxhighlight lang="jq">
# bag of words
def bow(stream):
Line 598 ⟶ 976:
def in_one_just_once:
bow( .[] | explode[] | [.] | implode) | with_entries(select(.value==1)) | keys;
</syntaxhighlight>
</lang>
'''The task'''
<langsyntaxhighlight lang="jq">["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
| in_one_just_once</langsyntaxhighlight>
{{out}}
<pre>
Line 608 ⟶ 986:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">list = ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
 
function is_once_per_all_strings_in(a::Vector{String})
Line 617 ⟶ 995:
 
println(is_once_per_all_strings_in(list))
</langsyntaxhighlight>{{out}}<pre>
['1', '5', '6', 'b', 'g', 's', 't', 'z']
</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:
 
<langsyntaxhighlight lang="julia">function uniquein(a)
counts = Dict{Char, Int}()
for c in prod(list)
Line 635 ⟶ 1,013:
@btime is_once_per_all_strings_in(list)
@btime uniquein(list)
</langsyntaxhighlight>{{out}}<pre>
['1', '5', '6', 'b', 'g', 's', 't', 'z']
1.740 μs (28 allocations: 3.08 KiB)
Line 642 ⟶ 1,020:
 
This can be rectified (see Phix entry) if we don't save the counts as we go but just exclude entries with duplicates:
<langsyntaxhighlight lang="julia">function uniquein2(a)
s = sort(collect(prod(list)))
l = length(s)
Line 651 ⟶ 1,029:
 
@btime uniquein2(list)
</langsyntaxhighlight>{{out}}<pre>
['1', '5', '6', 'b', 'g', 's', 't', 'z']
1.010 μs (14 allocations: 1.05 KiB)
</pre>
 
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">local strings = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}
unpack = unpack or table.unpack -- compatibility for all Lua versions
 
local map = {}
for i, str in ipairs (strings) do
for i=1, string.len(str) do
local char = string.sub(str,i,i)
if map[char] == nil then
map[char] = true
else
map[char] = false
end
end
end
 
local list = {}
for char, bool in pairs (map) do
if bool then
table.insert (list, char)
end
end
table.sort (list)
print (unpack (list))</syntaxhighlight>
{{out}}<pre>1 5 6 b g s t z</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">Select[Tally[Sort[Characters[StringJoin[{"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}]]]], Last /* EqualTo[1]][[All, 1]]</syntaxhighlight>
{{out}}
<pre>{"1", "5", "6", "b", "g", "s", "t", "z"}</pre>
 
=={{header|Nim}}==
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”.
 
<langsyntaxhighlight Nimlang="nim">import algorithm, sugar, tables
 
var charCount: CountTable[char]
Line 670 ⟶ 1,082:
if count == 1: ch
 
echo sorted(uniqueChars)</langsyntaxhighlight>
 
{{out}}
<pre>@['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>
 
=={{header|Pascal}}==
{{works with|Extended Pascal}}
<syntaxhighlight lang="pascal">program uniqueCharacters(output);
 
type
{ `integer…` prefix to facilitate sorting in documentation tools }
integerNonNegative = 0..maxInt;
{ all variables of this data type will be initialized to `1` }
integerPositive = 1..maxInt value 1;
charFrequency = array[char] of integerNonNegative;
{ This “discriminates” the `string` _schema_ data type. }
line = string(80);
{ A schema data type definition looks sort of like a function: }
lines(length: integerPositive) = array[1..length] of line;
 
{ `protected` in Extended Pascal means, you can’t modify this parameter. }
function createStatistics(protected sample: lines): charFrequency;
var
i, n: integerPositive;
{ The `value …` clause will initialize this variable to the given value. }
statistics: charFrequency value [chr(0)..maxChar: 0];
begin
{ You can inspect the discriminant of schema data type just like this: }
for n := 1 to sample.length do
begin
{ The length of a `string(…)` though needs to be queried: }
for i := 1 to length(sample[n]) do
begin
statistics[sample[n, i]] := statistics[sample[n, i]] + 1
end
end;
{ There needs to be exactly one assignment to the result variable: }
createStatistics := statistics
end;
 
{ === MAIN ============================================================= }
var
c: char;
sample: lines(3) value [1: '133252abcdeeffd';
2: 'a6789798st'; 3: 'yxcdfgxcyz'];
statistics: charFrequency;
begin
statistics := createStatistics(sample);
for c := chr(0) to maxChar do
begin
{
The colon (`:`) specifies the display width of the parameter.
While for `integer` and `real` values it means the _minimum_ width,
for `string` and `char` values it is the _exact_ width.
}
write(c:ord(statistics[c] = 1))
end;
writeLn
end.</syntaxhighlight>
{{out}}
<pre>156bgstz</pre>
 
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl"># 20210506 Perl programming solution
 
use strict;
Line 689 ⟶ 1,163:
"133252abcdeeffd", "a6789798st", "yxcdfgxcyz", "AАΑSäaoö٥🤔👨‍👩‍👧‍👧";
my $uca = Unicode::Collate->new();
print $uca->sort ( grep { $seen{$_} == 1 } keys %seen )</langsyntaxhighlight>
{{out}}
<pre>
Line 696 ⟶ 1,170:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="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: #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 706 ⟶ 1,180:
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 713 ⟶ 1,187:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de uni (Lst
(let R NIL
(mapc
Line 731 ⟶ 1,205:
"133252abcdeeffd"
"a6789798st"
"yxcdfgxcyz" ) ) )</langsyntaxhighlight>
{{out}}
<pre>
Line 738 ⟶ 1,212:
 
=={{header|PL/M}}==
<langsyntaxhighlight lang="pli">100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
Line 786 ⟶ 1,260:
CALL PRINT(.BUFFER);
CALL EXIT;
EOF</langsyntaxhighlight>
{{out}}
<pre>156BGSTZ</pre>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">'''Unique characters'''
 
from itertools import chain, groupby
Line 799 ⟶ 1,273:
def uniques(xs):
'''Characters which occur only once
across the given list of given strings.
'''
return [
kh for kh, g(_, *tail) in
groupby(sorted(chain(*xs)))
if 1not == len(list(g))tail
]
 
Line 825 ⟶ 1,299:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>
 
Or reducing the given strings down to a hash of character frequencies:
<syntaxhighlight lang="python">'''Unique characters'''
 
from functools import reduce
 
 
# uniqueChars :: [String] -> [Char]
def uniqueChars(ws):
'''Characters which occur only once
across the given list of strings.
'''
def addedWord(dct, w):
return reduce(updatedCharCount, w, dct)
 
def updatedCharCount(a, c):
return dict(
a, **{
c: 1 + a[c] if c in a else 1
}
)
 
return sorted([
k for k, v in reduce(addedWord, ws, {}).items()
if 1 == v
])
 
 
# ------------------------- TEST -------------------------
# main :: IO ()
def main():
'''Test'''
print(
uniqueChars([
"133252abcdeeffd",
"a6789798st",
"yxcdfgxcyz"
])
)
 
 
# MAIN ---
if __name__ == '__main__':
main()</syntaxhighlight>
{{Out}}
<pre>['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ [] swap
witheach join
[] 0 128 of
rot witheach
[ 2dup peek
1+ unrot poke ]
witheach
[ 1 = if
[ i^ join ] ] ] is task ( [ --> $ )
 
[]
$ "133252abcdeeffd" nested join
$ "a6789798st" nested join
$ "yxcdfgxcyz" nested join
 
task echo$</syntaxhighlight>
 
{{out}}
 
<pre>156bgstz</pre>
 
=={{header|Raku}}==
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.
 
<syntaxhighlight lang="raku" perl6line>my @list = <133252abcdeeffd a6789798st yxcdfgxcyz>;
 
for @list, (@list, 'AАΑSäaoö٥🤔👨‍👩‍👧‍👧') {
Line 839 ⟶ 1,382:
"\n (DUCET) Unicode collation order: ",
.map( *.comb ).Bag.grep( *.value == 1 )».key.collate.join, "\n";
}</langsyntaxhighlight>
{{out}}
<pre>133252abcdeeffd a6789798st yxcdfgxcyz
Line 859 ⟶ 1,402:
 
On an &nbsp;'''EBCDIC'''&nbsp; machine, &nbsp; the lowercase letters and the uppercase letters &nbsp; aren't &nbsp; contiguous.
<langsyntaxhighlight 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*/
if $='' | $="," then $= '133252abcdeeffd' "a6789798st" 'yxcdfgxcyz' /*use defaults.*/
Line 877 ⟶ 1,420:
say 'unique characters are: ' @ /*display the unique characters found. */
say
say 'Found ' L " unique characters." /*display the # of unique chars found. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 886 ⟶ 1,429:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see "working..." + nl
see "Unique characters are:" + nl
Line 919 ⟶ 1,462:
end
return sum
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 927 ⟶ 1,470:
Found 8 unique characters
done...
</pre>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
≪ DUP SIZE → string length
≪ 1 length '''FOR''' n
string n DUP SUB
'''NEXT'''
length 1 '''FOR''' n
1 n 1 - START
'''IF''' DUP2 ≥ '''THEN''' SWAP '''END'''
n ROLLD
'''NEXT'''
n ROLLD
-1 '''STEP'''
2 length '''START''' + '''NEXT'''
≫ ≫
‘SORTS’ STO
≪ DUP 1 DUP SUB → str char1
≪ str SIZE
'''IF''' DUP 1 >
'''THEN'''
DROP 1
'''WHILE''' str OVER 1 + DUP SUB char1 == '''REPEAT''' 1 + '''END'''
'''END'''
char1
≫ ≫
‘OCHST’ STO
≪ "" 1 3 PICK SIZE '''FOR''' j
OVER j GET +
'''NEXT'''
SWAP DROP
SORTS "" SWAP 1
'''WHILE''' OVER SIZE OVER ≥ '''REPEAT'''
DUP2 OVER SIZE SUB OCHST
'''IF''' OVER 1 ==
'''THEN''' 5 ROLL SWAP + 4 ROLLD
'''ELSE''' DROP
'''END'''
+
'''END'''
DROP2
‘UNCHR’ STO
===Shorter code but increased memory requirements===
≪ → strings
≪ { 255 } 0 CON 1 strings SIZE '''FOR''' j
strings j GET 1 OVER SIZE '''FOR''' k
DUP k DUP SUB NUM ROT SWAP DUP2 GET 1 + PUT SWAP
'''NEXT'''
DROP
'''NEXT'''
"" 1 255 '''FOR''' j
'''IF''' OVER j GET 1 == '''THEN''' j CHR + '''END'''
'''NEXT'''
SWAP DROP
‘UNCHR’ STO
 
{"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"} UNCHR
{{out}}
<pre>
1: "156bgstz"
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">words = ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
 
counter = words.inject({}){|h, word| word.chars.tally(h)}
puts counter.filter_map{|char, count| char if count == 1}.sort.join
</syntaxhighlight>
{{out}}
<pre>
156bgstz
</pre>
=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd
 
MainModule: {
v: ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"],
 
_start: (λ
(for p in (group-by (split (join v "") "")) do
(if (== (size (snd p)) 1) (textout (fst p))))
)
}</syntaxhighlight>
{{out}}
<pre>
156bgstz
</pre>
 
=={{header|Standard ML}}==
Using an Array:
<syntaxhighlight lang="sml">
fun uniqueChars xs =
let
val arr = Array.array(256, 0)
val inc = (fn c => Array.update(arr, ord c, Array.sub(arr, ord c)+1))
val _ = List.app inc (List.concat (List.map String.explode xs))
val ex1 = (fn (i,n,a) => if n=1 then (chr i)::a else a)
in
String.implode (Array.foldri ex1 [] arr)
end
</syntaxhighlight>
{{out}}
<pre>
- uniqueChars ["133252abcdeeffd","a6789798st","yxcdfgxcyz"];
val it = "156bgstz" : string
</pre>
 
A different approach:
<syntaxhighlight lang="sml">
(*
group [1,1,2,4,4,4,2,2,2,1,1,1,3]
=> [[1,1], [2], [4,4,4], [2,2,2], [1,1,1], [3]]
*)
fun group xs =
let
fun collectGroups(a,[]) = [[a]]
| collectGroups(a,b::bs) = if a = (hd b) then (a::b)::bs else [a]::b::bs
in
List.foldr collectGroups [] xs
end
 
fun uniqueChars2 xs =
let
(* turn the strings into one big list of characters *)
val cs = List.concat (List.map String.explode xs)
(* sort the big list of characters *)
val scs = ListMergeSort.sort Char.> cs
(* collect the groups *)
val gs = group scs
(* filter out groups with more than one member *)
val os = List.filter (fn a => null (tl a)) gs
in
String.implode (List.concat os)
end
</syntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">
fn main() {
strings := ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
mut m := map[rune]int{}
for s in strings {
for c in s {
m[c]++
}
}
mut chars := []rune{}
for k, v in m {
if v == 1 {chars << k}
}
chars.sort_with_compare(fn(i &rune, j &rune) int {
if *i < *j {return -1}
if *i > *j {return 1}
return 0
})
println(chars.string())
}
</syntaxhighlight>
 
{{out}}
<pre>
156bgstz
</pre>
 
Line 932 ⟶ 1,643:
{{libheader|Wren-seq}}
{{libheader|Wren-sort}}
<langsyntaxhighlight ecmascriptlang="wren">import "./seq" for Lst
import "./sort" for Sort
 
var strings = ["133252abcdeeffd", "a6789798st","yxcdfgxcyz"]
Line 940 ⟶ 1,651:
Sort.insertion(uniqueChars)
System.print("Found %(uniqueChars.count) unique character(s), namely:")
System.print(uniqueChars.join(" "))</langsyntaxhighlight>
 
{{out}}
Line 947 ⟶ 1,658:
1 5 6 b g s t z
</pre>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">dim c(255)
data "133252abcdeeffd", "a6789798st", "yxcdfgxcyz", ""
repeat
read s$
for i = 1 to len(s$)
a = asc(mid$(s$,i,1))
c(a) = c(a) + 1
next i
until s$ = ""
 
for i = 1 to 255
if c(i) = 1 then s$ = s$ + chr$(i) : fi
next i
print s$
end</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">int List, I, N, C;
char Tbl(128), Str;
string 0;
Line 965 ⟶ 1,699:
for I:= 0 to 127 do
if Tbl(I) = 1 then ChOut(0, I);
]</langsyntaxhighlight>
 
{{out}}
23

edits