156 123 bytes
Super interesting solution. Working on a proper one.
Saved 33 bytes thanks to @Giuseppe.
R (+ numbers and gmp), 198 bytes
Proper solution. Takes
n as input.
numbers::dropletPi(50) to generate the first 50 decimal places of pi.
gsub removes the decimal point.
substring takes every possible substring (surprise surprise) of pi up to
The returned list is flattened and converted to
bigz format. This format is required to store integers of length 50.
unique takes the unique values of that vector. This result gets stored in
Then we check for primality. This is tricky, because there are a bunch of edge-cases and annoyances:
n, there is a
0 in pi. This leads to substrings with a leading zero.
NAs with that, which have to be removed.
On a similar note, the substring
"0" will crash
gmp::factorize, so has to be removed as well.
x = 3. Which in itself is ok, but the
bigz representation of
3 is iterable, so
sapply will get confused and report 16 primes. To this end we take the minimum of the length of the vector
x, and the amount of primes in it.
gmp::isprime can't seem to reliably handle the large numbers reliably. So instead we use
gmp::factorize and check of the length of the output is 1.
So in all, we remove
x. We factorize all of
x and check for the length. We count the number of occurrences of
1 and return the