[VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
|
04-14-2019, 07:57 PM
Post: #38
|
|||
|
|||
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
Somehow I had completely missed Tier 2 until I saw Bernd's post #35. Then I thought I had a good program until I saw Albert's reply and realized the uniqueness requirement, so back to the drawing board.
This problem turns out to be a good fit for the 50g and the Prime, both of which have NEXTPRIME and ISPRIME? as built-in functions. My program also uses the I->BL command plus a couple of other commands from ListExt. I have tried to keep stackrobatics to a minimum in the interest of readability. %%HP: T(3)A(R)F(.); \<< I\->R \-> b n \<< { } 1 1. n START NEXTPRIME DUP b I\->BL LSUM DUP IF ISPRIME? THEN DROP ELSE ROT SWAP DUP2 IF POS THEN DROP SWAP ELSE + OVER + SWAP END END NEXT DROP DUP SIZE 2. / LDIST EVAL \>> \>> Inputs are the base on level 2 and the number of primes to check on level 1. Output are two separate lists, the composites and the primes. I would classify the size (163 bytes) and speed as reasonable if not exactly prize-winning, and it is sort of cheating as it uses so many pre-existing commands. I shudder to think of writing such a program on a "classic" era machine. I have checked the first 100000 primes for 7 and 31, which take over 5 minutes each on the emulator, so my results are nowhere near as extensive as Albert's. Still a neat problem, I only wish I had noticed it earlier. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 7 Guest(s)