MC: Ping-Pong Cubes
|
05-22-2018, 08:46 PM
(This post was last modified: 06-23-2018 09:09 PM by Valentin Albillo.)
Post: #4
|
|||
|
|||
RE: MC: Ping-Pong Cubes
.
Hi, Joe: (05-22-2018 03:16 PM)Joe Horn Wrote: The first 5 Ping-Pong Cubes are: Easy as pie. The following 4-liner (159 bytes) I've written for the HP-71B plus HP's String LEX does the job and finds all 10 such numbers less than 1,000 in 0.43 sec. under J-F's Emu71: 1 A$="10101010101" @ FOR I=10 TO 999 @ IF NOT FNP(I) THEN 2 ELSE IF FNP(I^3) THEN DISP I;I^3 2 NEXT I 3 DEF FNP(N) @ N$=STR$(VAL(REPLACE$(STR$(N),"9","1"))+VAL(A$[1,LEN(STR$(N))])) 4 IF SPAN(N$,"13579") THEN FNP=NOT SPAN(N$,"02468") ELSE FNP=1 >SETTIME 0 @ CALL @ TIME 18 5832 23 12167 85 614125 87 658503 101 1030301 103 1092727 301 27270901 303 27818127 363 47832147 725 381078125 0.43 sec. FNP is a 2-line user-defined function that returns 1 (True) if its argument is a PPN and 0 (False) if it isn't. Notice that it doesn't use any kind of looping at all, it gets the answer straight away, in linear time. Looking for all such numbers less than 10,000 takes less than 5 seconds but finds no additional ones. Quote:A much bigger challenge, which has eluded me thus far, is to find the 11th Ping-Pong Cube. It must be very large, if it even exists. My program would find it in principle but it's limited to the 12-digit native floating point results so searching for N>=10,000 would take multiprecision computations. I'll give it a try if I find the time. Regards. V. . P.S.: Edited to feature an improved version (4 lines instead of 5 and also somewhat faster). All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)