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: \<< 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. 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: :: ...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 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)