Permutations with repetitions

We can use the X operator ("cartesian product") to cross the list with itself.

For image:

my @k = <a b c>;

.say for @k X @k;

For arbitrary image:

my @k = <a b c>;
my $n = 2;

.say for [X] @k xx $n;

Output:

a a
a b
a c
b a
b b
b c
c a
c b
c c

Here is an other approach, counting all image possibilities in base image:

my @k = <a b c>;
my $n = 2;

say @k[.polymod: +@k xx $n-1] for ^@k**$n

Output:

a a
b a
c a
a b
b b
c b
a c
b c
c c