Course of Raku / Advanced / More about built-in types / Sets, bags, and mixes / Exercises

Common elements

Problem

You are given two sets of fruit names:

my $a = set(<apple banana cherry>);
my $b = set(<banana cherry date>);

Compute their intersection and store it in a variable. Then print two lines: how many values the two sets have in common, and whether apple is one of those common values (it should not be).

Example

The program prints:

2
False

Solution

See the solution

Course navigation

Solution: Count the distinct   |   Solution: Common elements