Post Reply 
MC: Ping-Pong Cubes
05-25-2018, 08:20 PM
Post: #7
RE: MC: Ping-Pong Cubes
An interesting challenge, Joe. This has a similar feel to some of your past challenges (Pan-prime Cube and All-odd digits come to mind). I suspect that some of the optimizations from the Pan-prime cube challenge could be helpful for this one; in particular, knowing in advance that certain root digit suffixes will create invalid results might speed things up. I didn't take it that far, though.

Here's my "plain UserRPL" approach:
Code:
\<<
  {
    DUP 2. MOD SWAP 10. / IP 1.
    WHILE
      OVER
    REPEAT
      ROT PICK3 2. MOD
      SWAP OVER XOR
      ROT AND
      ROT 10. / IP SWAP
    END
    NIP NIP
  }
  0.
  10.
  WHILE
    OVER 10. <
  REPEAT
    IF
      PICK3 OVER
      SWAP EVAL
    THEN
      IF
        PICK3 OVER
        DUPDUP * *
        SWAP EVAL
      THEN
        SWAP 1. + SWAP
        DUP 4. ROLLD
      END
    END
     1. +
  END
  DROP2 DROP
\>>

The code within the list brackets above is a subroutine that takes a real number as input and returns a 1 if the input was valid, otherwise a 0. It simply checks the parity of each digit after the first to make sure it isn't the same as the previous one.

The basic approach was to execute a loop on sequential integers starting with 10, stopping only after the 10th solution is found. In each loop iteration, the root is checked for validity before proceeding to check the cube. I opted to skip some obvious code shortcuts due to their performance impact. That said, I'm sure there are much faster UserRPL implementations possible -- I hope others will post their own. Smile The above program completes in 24.6 seconds on my 50g.

For those who might like to compare a SysRPL approach, I submit the following translation of the above program. It uses the exact same approach as the UserRPL one above, and completes in less than half the time of the above at 9.6 seconds. Note: I use Debug4x, which doesn't require the code within a WHILE clause to be encapsulated in a ":: ... ;" block. You would have to add the :: and ; symbols to the WHILE clauses if you don't use Debug4x as your compiler:
Code:
::
   CK0NOLASTWD

   ( Valid Ping Pong Check )
   ' ::
      DUP %2 %MOD %0<> SWAP %10 %/ %IP TRUE
      BEGIN
         OVER %0<>
      WHILE
         ROT 3PICK %2 %MOD %0<>
         SWAPOVER XOR
         ROTAND
         ROT %10 %/ %IP SWAP
      REPEAT
      ROTROT2DROP
   ;

   ( count of solutions )
   BINT0

   ( bind local vars )
   FLASHPTR 2LAMBIND

   ( seed initial test )
   %10

   ( do until 10 solutions found )
   BEGIN
      1GETLAM BINT10 #<
   WHILE
      DUP 2GETEVAL IT ::
         DUPDUP DUP %* %* 2GETEVAL IT ::
            1GETLAM #1+ 1PUTLAM
            DUP
         ;
      ;
      %1+
   REPEAT

   ( drop the count )
   DROP

   ( abandon local vars )
   ABND
;


...and finally, to show how much time is spent in that laborious ping-pong validation, I replaced the validation subroutine from the previous SysRPL example with this Saturn code object to see how much improvement I could get. Using this brought the total time down to 1.26 seconds:
Code:
   CODEM
      SAVE
      A=DAT1 A
      AD1EX
      D1+5
      A=DAT1 W
      ST=1 0
      B=0 S
      B+1 S
      C=A M
      CSL W
      A-1 X
      C&B S
      D=C S
      {
         CSL W
         C&B S
         ?C=D S ->{ ST=0 0 }
         D=C S
         A-1 X
         UPNC
      }
      LOAD
      LA 03AC0
      ?ST=1 0 ->{ LA 03A81 }
      DAT1=A A
      RPL
   ENDCODE
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
MC: Ping-Pong Cubes - Joe Horn - 05-22-2018, 03:16 PM
RE: MC: Ping-Pong Cubes - Didier Lachieze - 05-22-2018, 03:52 PM
RE: MC: Ping-Pong Cubes - Joe Horn - 05-22-2018, 04:05 PM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 05-22-2018, 08:46 PM
RE: MC: Ping-Pong Cubes - Didier Lachieze - 05-23-2018, 12:14 PM
RE: MC: Ping-Pong Cubes - Werner - 05-24-2018, 01:19 PM
RE: MC: Ping-Pong Cubes - DavidM - 05-25-2018 08:20 PM
RE: MC: Ping-Pong Cubes - ijabbott - 05-25-2018, 10:55 PM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 05-25-2018, 11:45 PM
RE: MC: Ping-Pong Cubes - pier4r - 05-26-2018, 06:47 AM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 05-26-2018, 11:31 PM
RE: MC: Ping-Pong Cubes - pier4r - 05-27-2018, 08:13 AM
RE: MC: Ping-Pong Cubes - DavidM - 05-26-2018, 05:01 PM
RE: MC: Ping-Pong Cubes - Joe Horn - 05-27-2018, 05:06 AM
RE: MC: Ping-Pong Cubes - David Hayden - 05-27-2018, 04:48 PM
RE: MC: Ping-Pong Cubes - ijabbott - 05-27-2018, 06:50 PM
RE: MC: Ping-Pong Cubes - pier4r - 05-27-2018, 09:19 PM
RE: MC: Ping-Pong Cubes - brickviking - 05-27-2018, 10:33 PM
RE: MC: Ping-Pong Cubes - Juan14 - 05-26-2018, 08:19 PM
RE: MC: Ping-Pong Cubes - DavidM - 05-27-2018, 03:02 PM
RE: MC: Ping-Pong Cubes - brickviking - 05-27-2018, 10:05 AM
RE: MC: Ping-Pong Cubes - ijabbott - 05-27-2018, 12:30 PM
RE: MC: Ping-Pong Cubes - DavidM - 05-27-2018, 02:50 PM
RE: MC: Ping-Pong Cubes - pier4r - 05-27-2018, 11:15 PM
RE: MC: Ping-Pong Cubes - ijabbott - 05-29-2018, 08:07 PM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 06-01-2018, 01:16 AM
RE: MC: Ping-Pong Cubes - Warbucks - 06-03-2018, 04:26 AM
RE: MC: Ping-Pong Cubes - Joe Horn - 06-03-2018, 03:24 PM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 06-14-2018, 03:07 PM
RE: MC: Ping-Pong Cubes - Joe Horn - 06-15-2018, 02:12 AM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 06-20-2018, 09:30 PM
RE: MC: Ping-Pong Cubes - Joe Horn - 06-21-2018, 02:50 AM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 06-21-2018, 09:29 PM
RE: MC: Ping-Pong Cubes - ijabbott - 06-03-2018, 05:42 AM
RE: MC: Ping-Pong Cubes - pier4r - 06-03-2018, 12:29 PM
RE: MC: Ping-Pong Cubes - Werner - 06-15-2018, 04:52 AM
RE: MC: Ping-Pong Cubes - Joe Horn - 06-15-2018, 03:37 PM
RE: MC: Ping-Pong Cubes - ijabbott - 06-17-2018, 10:33 AM
RE: MC: Ping-Pong Cubes - brickviking - 06-21-2018, 03:22 AM
RE: MC: Ping-Pong Cubes - pier4r - 06-21-2018, 06:24 AM
RE: MC: Ping-Pong Cubes - Joe Horn - 06-22-2018, 04:40 AM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 06-25-2018, 08:45 PM
RE: MC: Ping-Pong Cubes - ijabbott - 06-25-2018, 09:48 PM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 06-26-2018, 09:43 PM
RE: MC: Ping-Pong Cubes - rprosperi - 06-27-2018, 12:38 AM
RE: MC: Ping-Pong Cubes - Massimo Gnerucci - 06-27-2018, 06:58 AM
RE: MC: Ping-Pong Cubes - Jim Horn - 06-26-2018, 10:10 PM
RE: MC: Ping-Pong Cubes - Joe Horn - 06-26-2018, 10:23 PM
RE: MC: Ping-Pong Cubes - brickviking - 06-27-2018, 04:41 AM
RE: MC: Ping-Pong Cubes - Joe Horn - 06-27-2018, 05:23 AM
RE: MC: Ping-Pong Cubes - Valentin Albillo - 06-27-2018, 09:29 PM



User(s) browsing this thread: 1 Guest(s)