Unique characters: Difference between revisions
(Added Wren) |
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
||
Line 31: | Line 31: | ||
['1', '5', '6', 'b', 'g', 's', 't', 'z'] |
['1', '5', '6', 'b', 'g', 's', 't', 'z'] |
||
</pre> |
</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. |
|||
<lang perl6>my @list = <133252abcdeeffd a6789798st yxcdfgxcyz>; |
|||
for @list, (@list, 'AАΑSäaoö٥🤔👨👩👧👧') { |
|||
say "$_\nSemi-bogus \"Unicode natural sort\" order: ", |
|||
.map( *.comb ).Bag.grep( *.value == 1 )».key.sort( { .unival, .NFKD[0], .fc } ).join, |
|||
"\n (DUCET) Unicode collation order: ", |
|||
.map( *.comb ).Bag.grep( *.value == 1 )».key.collate.join, "\n"; |
|||
}</lang> |
|||
{{out}} |
|||
<pre>133252abcdeeffd a6789798st yxcdfgxcyz |
|||
Semi-bogus "Unicode natural sort" order: 156bgstz |
|||
(DUCET) Unicode collation order: 156bgstz |
|||
133252abcdeeffd a6789798st yxcdfgxcyz AАΑSäaoö٥🤔👨👩👧👧 |
|||
Semi-bogus "Unicode natural sort" order: 15٥6ASäbgoöstzΑА👨👩👧👧🤔 |
|||
(DUCET) Unicode collation order: 👨👩👧👧🤔ä15٥6AbögosStzΑА</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |
Revision as of 14:33, 5 May 2021
- Task
Given a list of strings find characters appearing only one string and once only.
The result give in alphabetical order.
Let list = ["133252abcdeeffd", "a6789798st","yxcdfgxcyz"]
Factor
<lang factor>USING: io sequences sets.extras sorting ;
{ "133252abcdeeffd" "a6789798st" "yxcdfgxcyz" } concat non-repeating natural-sort print</lang>
- Output:
156bgstz
Julia
<lang julia>list = ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]
function is_once_per_all_strings_in(a::Vector{String})
charlist = collect(prod(a)) counts = Dict(c => count(x -> c == x, charlist) for c in unique(charlist)) return sort([p[1] for p in counts if p[2] == 1])
end
println(is_once_per_all_strings_in(list))
</lang>
- Output:
['1', '5', '6', 'b', 'g', 's', 't', 'z']
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.
<lang perl6>my @list = <133252abcdeeffd a6789798st yxcdfgxcyz>;
for @list, (@list, 'AАΑSäaoö٥🤔👨👩👧👧') {
say "$_\nSemi-bogus \"Unicode natural sort\" order: ", .map( *.comb ).Bag.grep( *.value == 1 )».key.sort( { .unival, .NFKD[0], .fc } ).join, "\n (DUCET) Unicode collation order: ", .map( *.comb ).Bag.grep( *.value == 1 )».key.collate.join, "\n";
}</lang>
- Output:
133252abcdeeffd a6789798st yxcdfgxcyz Semi-bogus "Unicode natural sort" order: 156bgstz (DUCET) Unicode collation order: 156bgstz 133252abcdeeffd a6789798st yxcdfgxcyz AАΑSäaoö٥🤔👨👩👧👧 Semi-bogus "Unicode natural sort" order: 15٥6ASäbgoöstzΑА👨👩👧👧🤔 (DUCET) Unicode collation order: 👨👩👧👧🤔ä15٥6AbögosStzΑА
Ring
<lang ring> see "working..." + nl see "Unique characters are:" + nl row = 0 str = "" cList = [] uniqueChars = ["133252abcdeeffd", "a6789798st","yxcdfgxcyz"] for n = 1 to len(uniqueChars)
str = str + uniqueChars[n]
next for n = 1 to len(str)
ind = count(str,str[n]) if ind = 1 row = row + 1 add(cList,str[n]) ok
next cList = sort(cList) for n = 1 to len(cList)
see "" + cList[n] + " "
next see nl
see "Found " + row + " unique characters" + nl see "done..." + nl
func count(cString,dString)
sum = 0 while substr(cString,dString) > 0 sum++ cString = substr(cString,substr(cString,dString)+len(string(sum))) end return sum
</lang>
- Output:
working... Unique characters are: 1 5 6 b g s t z Found 8 unique characters done...
Wren
<lang ecmascript>import "/seq" for Lst import "/sort" for Sort
var strings = ["133252abcdeeffd", "a6789798st","yxcdfgxcyz"] var totalChars = strings.reduce { |acc, str| acc + str }.toList var uniqueChars = Lst.individuals(totalChars).where { |l| l[1] == 1 }.map { |l| l[0] }.toList Sort.insertion(uniqueChars) System.print("Found %(uniqueChars.count) unique character(s), namely:") System.print(uniqueChars.join(" "))</lang>
- Output:
Found 8 unique character(s), namely: 1 5 6 b g s t z