(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-
\>>