Vietnamese snake puzzle - Closed
05-28-2015, 09:20 PM
Post: #37
 Gerson W. Barbosa Senior Member Posts: 1,212 Joined: Dec 2013
RE: Vietnamese snake puzzle - Closed
(05-23-2015 09:08 AM)Werner Wrote:  Including the condition that
Code:
MOD(13*b*i + g*h*c,c*i)=0
after having selected 5 numbers reduced the timing to 30 seconds.

I've changed to the condition FP(13*b/c + g*h/i)=0, which is simpler and uses four multiplication/division operations instead of six. Since I take 13*b/c from the stack, this is reduced to only one multiplication and one division in the inner loop. Also, local variables 'a', 'd' and 'f' are not defined anymore. Running times are now 1h 05m 32.9s on the HP-48GX and 21m 51.9s on the HP 50g. I should revert to my original innermost loop, which apparently is faster, but I prefer to optimize the current one later. I'd be pleased with less than one hour's time on the HP-48GX :-)

Cheers,

Gerson.

HP-48GX:

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 / DUP 87 - 1 7             FOR e e b \=/ e c \=/ AND e i \=/ AND               IF               THEN e 12 * OVER + 5 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 * i / 7 PICK + FP     IF NOT     THEN \-> g h       \<< 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 SWAP ROT ROT b c ROT e 5 ROLL g h i 9 \->LIST 1 \->LIST 9 ROLL + 8 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 DROP2           END         NEXT       END     NEXT   NEXT SWAP DROP TIME ROT HMS- \>>

HP 50g:

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 / DUP 87. - 1. 7.             FOR e e b \=/ e c \=/ AND e i \=/ AND               IF               THEN e 12. * OVER + 5. 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 * i / 7. PICK + FP                     IF NOT                     THEN \-> g h                       \<< 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 SWAP UNROT b c ROT e 5. ROLL g h i 9. \->LIST 1. \->LIST 9. ROLL + 8. 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 DROP2           END         NEXT       END     NEXT   NEXT NIP \>>
 « 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)