explanation comingThis is one of those situations for which I haven't yet found a good J solution.
Nevertheless, I post this in hopes of learning something new.
f
tells us if a given number is a "repeated digit prime". It breaks down as follows:
[:1&p: is the following a prime?
(*@ the signum of...
(*/) the product of the digits
* times...
x:@ force extended precision of...
#~) self-duplicated digits
&. "Under": perform this, then perform its inverse at the end
(10&#.inv) convert to a list of digits
And finally the main verb, with its pesky, seemingly unavoidable boilerplate, which arises from the fact that we need to use a list to store our progress, which requires both "current prime" and "found so far" registers, since our left argument is already taken to store the stopping condition, ie, n
. This means that we must use many precious bytes for the simple task of specifying args ([
and ]
) and unpacking our 2 element list ({.
and {:
):
[:{. take the first element of...
(4&p:@ the next prime after...
{.@ the first element of...
] the right arg
{:@]) the last (2nd) elm of the arg...
([,]+f@[) those two now become the left and right args to this verb...
[, left arg appended to...
]+ right arg plus...
f@[ f of the left arg...
^:( )^:_ keep doing all that while...
[> the left is bigger than...
{:@] the last elm of the right arg
&2 0 seed the process with 2 0, ie,
the first prime, and 0 rdps found so far.