aboutsummaryrefslogtreecommitdiff
path: root/challenge-057/markus-holzer/raku/ch-2.p6
blob: 75be57ebe3df161043407c8af616f1c7cbea317b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
my $words = [ "alphabet", "book", "carpet", "cadmium", "cadeau", "alpine" ];

.say for gather shortest-unique-prefixes( $words );

sub shortest-unique-prefixes( Array $words, Int $l = 1 )
{
    for $words.classify( *.substr(0, $l) )
    {
        take .key and next
            if .value.elems == 1;
        shortest-unique-prefixes( .value, $l + 1 )
    }
}