user
Task
:   :   1. Take an positive integer   **n**
        2. **sumn**   is the sum of the decimal digits of   **n**
        3. If  **sumn'**s  length is greater than   **1**   (unity),   repeat step 2 for   **n = sumn**
        4. Stop when  **sumn'**s  length is equal to   **1**   (unity)

If   **n**   and   **sumn**   are prime,   then   **n**   is a   **Nice prime**

Let     **500   <   n   <   1000**

Example

```
       853 (prime)
       8 + 5 + 3 = 16
       1 + 6 = 7 (prime)

```

Also see
:   :   * The OEIS article:   A78403 Primes such that digital root is prime.
assistant
```
sub digroot ($r) { .tail given $r, { [+] .comb } ... { .chars == 1 } }
my @is-nice = lazy (0..*).map: { .&is-prime && .&digroot.&is-prime ?? $_ !! False };
say @is-nice[500 ^..^ 1000].grep(*.so).batch(11)».fmt("%4d").join: "\n";

```

Output:

```
 509  547  563  569  587  599  601  617  619  641  653
 659  673  677  691  709  727  743  761  797  821  839
 853  857  887  907  911  929  941  947  977  983  997
```

Alternately, with somewhat better separation of concerns.

```
sub digroot ($r) { ($r, { .comb.sum } … { .chars == 1 }).tail }
sub is-nice ($_) { .is-prime && .&digroot.is-prime }
say (500 ^..^ 1000).grep( *.&is-nice ).batch(11)».fmt("%4d").join: "\n";

```

Same output.