Vietnamese snake puzzle - Closed
05-26-2015, 04:54 AM (This post was last modified: 05-26-2015 09:54 PM by Gerson W. Barbosa.)
Post: #34
 Gerson W. Barbosa Senior Member Posts: 1,383 Joined: Dec 2013
RE: Vietnamese snake puzzle - Closed
(05-25-2015 06:33 AM)Werner Wrote:
(05-24-2015 08:20 PM)Gerson W. Barbosa Wrote:  I think this is correct, but I haven't checked it yet.

It passes the test:

Code:
\<<   1   \<<     DUP EVAL \-> A B C D E F G H I '(13*B*I+G*H*C)/(C*I)+A+D-F+12*E'     IF 87 SAME THEN DROP END   \>>   DOLIST \>>

Though none of your solutions matches mine ;-) You take a different A/D order.

I tried to optimize the innermost loop so that one, two or three permutations of the candidates to a, d and f were made as needed, rather than always three, but the DO-UNTIL loop ended up being slower than START-NEXT. Now it takes almost one minute longer: 24 min 53 sec. The output list pass the test also, mainly because it's the same list, only with the elements in reverse order :-).
The two nested FOR-NEXT loops one level higher generate the 10 combinations [ C(5,2)] of the five candidates to g, h, a, d and f. An optimization here might help. The HP 50g has C2P, P2C and CIRC, but I don't know if those can be used for this purpose.

Cheers,

Gerson.

Code:
 %%HP: T(3)A(D)F(,); \<< { 1, 2, 3, 4, 5, 6, 7, 8, 9, } { } 1, 9,   FOR i 1, 9,     FOR c c i \=/       IF       THEN 1, 9,         FOR b b c \=/ b i \=/ AND           IF           THEN b 13, * c / 87, - 1, 7,             FOR e e b \=/ e c \=/ AND e i \=/ AND               IF               THEN e 12, * OVER + 4, PICK 1,                 \<<                   IF DUPDUP DUPDUP i == SWAP c == OR SWAP b == OR SWAP e == OR                   THEN DROP                   END                 \>> DOLIST 1, 4,                 FOR j j 1, + 5,                   FOR k DUP j GET OVER k GET DUP2 * c * b 13, * i * + i c * MOD                     IF NOT                     THEN 0, 0, 0, \-> g h a d f                       \<< g h * i / PICK3 + OVER 1,                         \<<                           IF DUPDUP g == SWAP h == OR                           THEN DROP                           END                         \>> DOLIST 0, 1, CF                         DO 1, + UNROT SWAP OVER OBJ\-> DROP + NEG + OVER - ABS ,000001 <                           IF                           THEN 1, SF OVER OBJ\-> DROP 'd' STO 'a' STO 'f' STO a b c d e f g h i 9, \->LIST 1, \->LIST 8, ROLL + 7, ROLLD                           END 1, FS? NOT                           IF                           THEN SWAP DUP HEAD SWAP TAIL SWAP + SWAP                           END UNROT SWAP DUP 3, == 1, FS? OR                         UNTIL                         END 3, DROPN                       \>>                     ELSE DROP2                     END                   NEXT                 NEXT DROP2               END             NEXT DROP           END         NEXT       END     NEXT   NEXT NIP \>>

P.S.:

Time on the HP 49G: 1h 09m 32s. 1h 12m 25s on the HP 48GX.

HP 48GX version:

Code:
 %%HP: T(3)A(D)F(.); \<< TIME { 1 2 3 4 5 6 7 8 9 } { } 1 9   FOR i 1 9     FOR c c i \=/       IF       THEN 1 9         FOR b b c \=/ b i \=/ AND           IF           THEN b 13 * c / 87 - 1 7             FOR e e b \=/ e c \=/ AND e i \=/ AND               IF               THEN e 12 * OVER + 4 PICK 1 \<<   IF DUP DUP DUP2 i == SWAP c == OR SWAP b == OR SWAP e == OR   THEN DROP   END \>> DOLIST 1 4 FOR j j 1 + 5   FOR k DUP j GET OVER k GET DUP2 * c * b 13 * i * + i c * MOD     IF NOT     THEN 0 0 0 \-> g h a d f       \<< g h * i / 3 PICK + OVER 1         \<<           IF DUP DUP g == SWAP h == OR           THEN DROP           END         \>> DOLIST 0 1 CF         DO 1 + ROT ROT SWAP OVER OBJ\-> DROP + NEG + OVER - ABS .000001 <           IF           THEN 1 SF OVER OBJ\-> DROP 'd' STO 'a' STO 'f' STO a b c d e f g h i 9 \->LIST 1 \->LIST 8 ROLL + 7 ROLLD           END 1 FS? NOT           IF           THEN SWAP DUP HEAD SWAP TAIL SWAP + SWAP           END ROT ROT SWAP DUP 3 == 1 FS? OR         UNTIL         END 3 DROPN       \>>     ELSE DROP2     END   NEXT NEXT DROP2               END             NEXT DROP           END         NEXT       END     NEXT   NEXT SWAP DROP TIME ROT HMS- \>>
 « Next Oldest | Next Newest »

 Messages In This Thread Vietnamese snake puzzle - Closed - Gerald H - 05-20-2015, 09:37 AM RE: Vietnamese snake puzzle - Dave Britten - 05-20-2015, 11:27 AM RE: Vietnamese snake puzzle - Gerald H - 05-20-2015, 11:33 AM RE: Vietnamese snake puzzle - Gerald H - 05-20-2015, 12:58 PM RE: Vietnamese snake puzzle - Closed - Dave Britten - 05-20-2015, 01:24 PM RE: Vietnamese snake puzzle - Closed - Gerald H - 05-20-2015, 01:30 PM RE: Vietnamese snake puzzle - Closed - Dave Britten - 05-20-2015, 01:35 PM RE: Vietnamese snake puzzle - Closed - Gilles - 05-20-2015, 09:01 PM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-21-2015, 04:04 AM RE: Vietnamese snake puzzle - Closed - Gerald H - 05-21-2015, 05:30 AM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-21-2015, 12:19 PM RE: Vietnamese snake puzzle - Closed - Tugdual - 05-21-2015, 08:12 AM RE: Vietnamese snake puzzle - Closed - Gerald H - 05-21-2015, 08:41 AM RE: Vietnamese snake puzzle - Closed - Tugdual - 05-21-2015, 10:51 AM RE: Vietnamese snake puzzle - Closed - Gerald H - 05-21-2015, 11:21 AM RE: Vietnamese snake puzzle - Closed - Tugdual - 05-21-2015, 11:53 AM RE: Vietnamese snake puzzle - Closed - fhub - 05-21-2015, 01:18 PM RE: Vietnamese snake puzzle - Closed - Tugdual - 05-21-2015, 01:51 PM RE: Vietnamese snake puzzle - Closed - Gerald H - 05-21-2015, 12:02 PM RE: Vietnamese snake puzzle - Closed - Tugdual - 05-21-2015, 12:29 PM RE: Vietnamese snake puzzle - Closed - Thomas Klemm - 05-21-2015, 01:14 PM RE: Vietnamese snake puzzle - Closed - Gerald H - 05-22-2015, 04:42 AM RE: Vietnamese snake puzzle - Closed - Tugdual - 05-22-2015, 12:04 PM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-22-2015, 08:00 PM RE: Vietnamese snake puzzle - Closed - Tugdual - 05-22-2015, 10:21 PM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-22-2015, 11:32 PM RE: Vietnamese snake puzzle - Closed - Werner - 05-23-2015, 09:08 AM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-24-2015, 03:14 AM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-24-2015, 08:20 PM RE: Vietnamese snake puzzle - Closed - Werner - 05-25-2015, 06:33 AM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-26-2015 04:54 AM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-28-2015, 09:20 PM RE: Vietnamese snake puzzle - Closed - Werner - 05-24-2015, 06:40 PM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-24-2015, 08:34 PM RE: Vietnamese snake puzzle - Closed - Gilles - 05-26-2015, 08:57 PM RE: Vietnamese snake puzzle - Closed - Gerald H - 05-25-2015, 07:14 AM RE: Vietnamese snake puzzle - Closed - Werner - 05-27-2015, 10:12 AM RE: Vietnamese snake puzzle - Closed - Werner - 05-29-2015, 07:14 AM RE: Vietnamese snake puzzle - Closed - Gerson W. Barbosa - 05-31-2015, 05:37 AM

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