user
Anaprimes are prime numbers that are anagrams of each other, i.e. they use exactly the same digits with the same frequency but in a different order.

Anaprimes are *very* common. To illustrate this, we will investigate the sizes of the equivalence classes defined by the "is an anagram of" relation.

For example, the equivalence class of 149 has four anaprimes: {149, 419, 491, 941}. It turns out that there is no larger equivalence class of 3-digit anaprimes.

Task

* Find prime numbers that are anagrams of each other.
* Find the **largest** anagram group of prime numbers and display the count, and minimum and maximum members for prime numbers:
  + up to three digits long (before 1,000)
  + up to four digits long (before 10,000)
  + up to five digits long (before 100,000)
  + up to six digits long (before 1,000,000)

Stretch

* Find the **largest** anagram group and display the count, and smallest and largest members for prime numbers:
  + up to seven digits long (before 10,000,000)
  + up to eight digits long (before 100,000,000)
  + up to nine digits long (before 1,000,000,000)
  + ???!

Related tasks

* Circular primes * Ormiston pairs * Emirp primes
assistant
9 digit is slooow. I didn't have the patience for 10.

```
use Lingua::EN::Numbers;
use Math::Primesieve;
use List::Allmax;

my $p = Math::Primesieve.new;

for 3 .. 9 {
    my @largest = $p.primes(10**($_-1), 10**$_).classify(*.comb.sort.join).List.&all-max(:by(+*.value)).values;

    put "\nLargest group of anaprimes before {cardinal 10 ** $_}: {+@largest[0].value} members.";
    put 'First: ', ' Last: ' Z~ .value[0, *-1] for sort @largest;
}

```

Output:

```
Largest group of anaprimes before one thousand: 4 members.
First: 149  Last: 941
First: 179  Last: 971
First: 379  Last: 937

Largest group of anaprimes before ten thousand: 11 members.
First: 1237  Last: 7321
First: 1279  Last: 9721

Largest group of anaprimes before one hundred thousand: 39 members.
First: 13789  Last: 98731

Largest group of anaprimes before one million: 148 members.
First: 123479  Last: 974213

Largest group of anaprimes before ten million: 731 members.
First: 1235789  Last: 9875321

Largest group of anaprimes before one hundred million: 4,333 members.
First: 12345769  Last: 97654321

Largest group of anaprimes before one billion: 26,519 members.
First: 102345697  Last: 976542103
```