Post Reply 
Vietnamese snake puzzle - Closed
05-31-2015, 05:37 AM
Post: #39
RE: Vietnamese snake puzzle - Closed
(05-29-2015 07:14 AM)Werner Wrote:  
Quote:I've changed to the condition FP(13*b/c + g*h/i)=0

Yes, I changed it to avoid rounding errors, but it turns out in the 48's decimal arithmetic we don't have any - in hindsight ;-)

My latest posted routine to find the 5 'full integer' solutions runs in 375 seconds on the EMU48 at 'authentic speed' setting, which should not be far off.
To find all solutions it needs approx. 1212 seconds or 20 minutes.

Cheers, Werner

In addition to the condition e < 8, now I am using -17 < (f - a - d) < 7, which I had done when manually searching for a solution. Now the primary 34 solutions are found in 52m 15.9s on the HP-48GX and in 17m 38.7s on the HP 50g (17m 40.4s in the HP 50g version using DO-UNTIL instead of START-NEXT - definitely not worth in this case since most f, a, d in agreement with the second condition will have to be permutated three times anyway).
I think finding all solutions under one hour's time on the HP-48GX is quite acceptable :-)

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 + DUP DUP -16
< SWAP 6 > OR
        IF
        THEN DROP
        ELSE OVER 1
          \<<
            IF DUP
DUP g == SWAP h ==
OR
            THEN
DROP
            END
          \>> DOLIST
1 3
          START DUP
TAIL OVER HEAD + 3
PICK ROT OBJ\-> DROP
+ NEG + - ABS
.000001 <
            IF
            THEN
DUP OBJ\-> DROP ROT
ROT b c ROT e 6
ROLL g h i 9 \->LIST
1 \->LIST 8 ROLL + 7
ROLLD
            END
          NEXT
DROP2
        END
      \>>
    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 + DUPDUP -16. < SWAP 6. > OR
                        IF
                        THEN DROP
                        ELSE OVER 1.
                          \<<
                            IF DUPDUP g == SWAP h == OR
                            THEN DROP
                            END
                          \>> DOLIST 1. 3.
                          START DUP TAIL OVER HEAD + PICK3 ROT OBJ\-> DROP + NEG + - ABS .000001 <
                            IF
                            THEN DUP OBJ\-> DROP UNROT b c ROT e 6. ROLL g h i 9. \->LIST 1. \->LIST 8. ROLL + 7. ROLLD
                            END
                          NEXT DROP2
                        END
                      \>>
                    ELSE DROP2
                    END
                  NEXT
                NEXT DROP2
              END
            NEXT DROP2
          END
        NEXT
      END
    NEXT
  NEXT NIP
\>>


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 + DUPDUP -16. < SWAP 6. > OR
                        IF
                        THEN DROP
                        ELSE OVER 1.
                          \<<
                            IF DUPDUP g == SWAP h == OR
                            THEN DROP
                            END
                          \>> DOLIST 0.
                          DO 1. + UNROT SWAP OVER OBJ\-> DROP + NEG + OVER - ABS .000001 <
                            IF
                            THEN 3. DUP UNPICK OVER OBJ\-> DROP SWAP UNROT b c ROT e 5. ROLL g h i 9. \->LIST 1. \->LIST 9. ROLL + 8. ROLLD
                            END OVER TAIL ROT HEAD + ROT DUP 3. ==
                          UNTIL
                          END 3. DROPN
                        END
                      \>>
                    ELSE DROP2
                    END
                  NEXT
                NEXT DROP2
              END
            NEXT DROP2
          END
        NEXT
      END
    NEXT
  NEXT NIP
\>>
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
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 - Gerson W. Barbosa - 05-31-2015 05:37 AM



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