A version using list processing with ListExt commands:
Code:
Unspoiled...
\<<
2. DUP ROT LASEQ
0. NEXTPRIME SWAP
IF
DUP SIZE
THEN
1.
\<<
OVER
{ NEXTPRIME }
ROT LMRPT
EVAL
\>>
DOSUBS
END
+
\>>
This one weighs in at 97.5 bytes, and finishes an input of
99 in about 383 seconds on my 50g. Two commands from the
ListExt library are used: LASEQ and LMRPT. LASEQ is used
to generate a list of even numbers from { 2..n }, where
the total count of numbers is the input parameter k. In
the case of an input of 99, LASEQ generates the list { 2.
4. 6. 8. ... 198. } in about 43 milliseconds.
LMRPT is used to replicate NEXTPRIME in a list a given
number of times (in this case each of the above even
numbers). So given { NEXTPRIME } and 4 as arguments, LMRPT
creates this list: { NEXTPRIME NEXTPRIME NEXTPRIME
NEXTPRIME }. That result is then executed on a copy of the
last found prime to generate the next one.
Ultimately, all of these RPL programs are at the mercy of
the NEXTPRIME command, which I believe consumes the
majority of processing time. This version achieves a minor
speed advantage by reducing the overall looping overhead
as compared to other versions. It does this at the cost of
a large memory footprint at runtime, though. Using a
k-value of 99 means that a list of 198 NEXTPRIME commands
is created (and executed) for the final pass of the DOSUBS
loop. That list alone is over 2K (bytes) in size!