Course of Raku / Advanced / More about built-in types / Sets, bags, and mixes / Exercises / Count the distinct
Solution: Count the distinct
Here is a possible solution to the task.
Code
my @data = 3, 1, 4, 1, 5, 9, 2, 6, 5, 3;
say set(@data).elems;🦋 You can find the source code in the file count-the-distinct.raku.
Output
7Comments
Passing the array to
setbuilds a set of its values. Because a set keeps only distinct values, the repeated numbers collapse into one.The
elemsmethod then returns the number of distinct values, which is7.