Vietnamese snake puzzle - Closed
|
05-22-2015, 08:00 PM
(This post was last modified: 05-23-2015 06:36 PM by Gerson W. Barbosa.)
Post: #24
|
|||
|
|||
RE: Vietnamese snake puzzle - Closed
An RPL solution, basically what I did by hand, except that I was a bit smarter and didn't go through some impossible alternatives. But the hp 50g is much faster than I am, so no problem: less than four minutes to find four solutions which can be expanded to more by applying commutative properties of multiplication and addition (9 seconds on the emulator). Writing the program took a bit longer, however, no to mention I lost more the more complicated inner structers last night, by accidentally replacing it with something else. No backups, no notes as it had been done right on the calculator only.
Conclusion: better do this by hand :-) Code:
{ [ 9. 4. 1. 5. 2. 7. 3. 8. 6. ] [ 3. 2. 1. 5. 4. 7. 8. 9. 6. ] [ 7. 3. 1. 5. 2. 6. 8. 9. 4. ] [ 6. 3. 1. 9. 2. 5. 7. 8. 4. ] } This should work on the HP-48G also, only remember to make this changes and others I may have forgotten: NIP: SWAP DROP DUPDUP: DUP DUP PICK3: 3 PICK Gerson. Edited to fix the range of the loops. I had found an incredible 50-second runtime but the outer loops were ranging from 2 to 6, 2 to 4 and 2 to 8, respectively, and yet the program returned the same four solutions. Something to be explored and analyzed to improve the program. There is still room for improvement such as better list handling, for instance. P.S.: Considering our equation is a + 13*b + d + 12*e - f - 11 + g*h/i = 76 We can write the following table: b e f| result -----+------- 9 x 8| > 109 8 x 9| > 95 7 2 9| > 106 6 2 9| > 90 => b < 6 x 9 8| > 100 x 8 9| > 87 => e < 8 5 7 9| > 140 5 6 9| > 120 4 5 9| > 106 3 5 9| > 90 => e < 5 Now we can safely define the ranges of the outer loops and be sure we won't miss any solution: Code:
{ [ 9. 4. 1. 5. 2. 7. 3. 8. 6. ] [ 3. 2. 1. 5. 4. 7. 8. 9. 6. ] [ 7. 3. 1. 5. 2. 6. 8. 9. 4. ] [ 6. 3. 1. 9. 2. 5. 7. 8. 4. ] } 33.6 seconds on the physical HP 50g! This matches Tugdual's results when c=1, considering all valid permutations: 941527386 941527836 541927836 541927386 321547896 321547986 521347986 521347896 731526894 731526984 531726984 531726894 631925874 631925784 931625874 931625784 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)