# Permutations with repetitions

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

For n = 2 {\displaystyle n=2} ![{\displaystyle n=2}](https://wikimedia.org/api/rest_v1/media/math/render/svg/a02c8bd752d2cc859747ca1f3a508281bdbc3b34):

```perl
my @k = <a b c>;

.say for @k X @k;
```

For arbitrary n {\displaystyle n} ![{\displaystyle n}](https://wikimedia.org/api/rest_v1/media/math/render/svg/a601995d55609f2d9f5e233e36fbe9ea26011b3b):

```perl
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 k n {\displaystyle k^{n}} ![{\displaystyle k^n}](https://wikimedia.org/api/rest_v1/media/math/render/svg/29d0ca5fd176db2867ec07a961a31f17bc6fb07e) possibilities in base k {\displaystyle k} ![{\displaystyle k}](https://wikimedia.org/api/rest_v1/media/math/render/svg/c3c9a2c7b599b37105512c5d570edc034056dd40):

```perl
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
```
