Unique characters: Difference between revisions

Content added Content deleted
(Added Arturo implementation)
Line 203: Line 203:
1.010 μs (14 allocations: 1.05 KiB)
1.010 μs (14 allocations: 1.05 KiB)
</pre>
</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”.

<lang Nim>import algorithm, sugar, tables

var charCount: CountTable[char]

for str in ["133252abcdeeffd", "a6789798st", "yxcdfgxcyz"]:
charCount.merge str.toCountTable

let uniqueChars = collect(newSeq):
for ch, count in charCount.pairs:
if count == 1: ch

echo sorted(uniqueChars)</lang>

{{out}}
<pre>@['1', '5', '6', 'b', 'g', 's', 't', 'z']</pre>


=={{header|Perl}}==
=={{header|Perl}}==