Post Reply 
Mini-challenge: digits by half
03-30-2022, 11:32 AM (This post was last modified: 03-30-2022 11:47 AM by DavidM.)
Post: #10
RE: Mini-challenge: digits by half
Solving this puzzle with just the naive approach is still "within reach" of the later hp calculators. This focuses on a 50g implementation.

The ListExt library has a couple of useful commands for this. The following was quite easy to conceive -- I spent more time trying to figure out how to keep the calculator from automatically simplifying the fraction than anything else.

I ended up avoiding the simplification by manually building the algebraic fraction as a list and using the built-in development library's →ALG function to convert it to an algebraic. If you don't normally have the development library attached, you may need to do that first with "256 ATTACH".

Code:
\<<
   9 LSEQ { 1 6 } LRMOV             @ digits for permutation
   DUP SIZE                         @ use all digits for each permutation
   \<<
      3 SPLIT                       @ split permutation into lists of 3 and 4
      6 ROT + NL\->I                @ prefix fixed digits (6 & 1), convert to
      1 ROT + NL\->I                @  integers
      2 \->LIST { / } + \->ALG      @ convert integers to algebraic fraction
      DUP \->NUM .5 SAME NOT DROPN  @ DROP the fraction if <> 1/2
   \>>
   DOPERM                           @ execute the above for each permutation
\>>

The output is "{ '6729/13458' '6792/13584' '6927/13854' }". It takes about 670 seconds on a real 50g.

I suspect NewRPL or Prime versions would complete in a fraction of that time (pun slightly intended). Using some of the aforementioned optimizations would help considerably, of course. But even the "check every permutation" approach with 7 digits floating is reasonable.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Mini-challenge: digits by half - Allen - 03-28-2022, 10:34 PM
RE: Mini-challenge: digits by half - DavidM - 03-30-2022 11:32 AM



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