Unique characters: Difference between revisions

Add two StandardML versions
(Add two StandardML versions)
 
(2 intermediate revisions by 2 users not shown)
Line 1,348:
{{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}}==
Line 1,540 ⟶ 1,563:
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)}}==
Line 1,572 ⟶ 1,643:
{{libheader|Wren-seq}}
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "./seq" for Lst
import "./sort" for Sort
 
var strings = ["133252abcdeeffd", "a6789798st","yxcdfgxcyz"]
Line 1,587 ⟶ 1,658:
1 5 6 b g s t z
</pre>
 
 
=={{header|Yabasic}}==
23

edits