DECLARE SUB permute (a$)
CLS
a$ = "1234567890": h$ = a$
DO
p = VAL(MID$(a$, 1, 1))
o = VAL(MID$(a$, 2, 1))
l = VAL(MID$(a$, 3, 1))
s = VAL(MID$(a$, 4, 1))
k = VAL(MID$(a$, 5, 1))
a = VAL(MID$(a$, 6, 1))
r = VAL(MID$(a$, 7, 1))
w = VAL(MID$(a$, 8, 1))
n = VAL(MID$(a$, 9, 1))
e = VAL(MID$(a$, 10, 1))
polska = VAL(LEFT$(a$, 6))
krakow = 100100 * k + 10000 * r + 1000 * a + 10 * o + w
answer = 100000 * a + 10000 * n + 1000 * s + 100 * w + 10 * e + r
IF polska + krakow = answer THEN PRINT polska; krakow; answer
permute a$
LOOP UNTIL a$ = h$
PRINT "paused"
PRINT : PRINT
DO: LOOP UNTIL INKEY$ > ""
part2:
a$ = "1234567890": h$ = a$
DO
p = VAL(MID$(a$, 1, 1))
o = VAL(MID$(a$, 2, 1))
l = VAL(MID$(a$, 3, 1))
s = VAL(MID$(a$, 4, 1))
k = VAL(MID$(a$, 5, 1))
a = VAL(MID$(a$, 6, 1))
r = VAL(MID$(a$, 7, 1))
w = VAL(MID$(a$, 8, 1))
n = VAL(MID$(a$, 9, 1))
e = VAL(MID$(a$, 10, 1))
polska = VAL(LEFT$(a$, 6))
sr = INT(SQR(polska) + .5)
IF sr * sr = polska THEN
krakow = 100100 * k + 10000 * r + 1000 * a + 10 * o + w
sum = polska + krakow
IF sum >= max THEN
PRINT polska, krakow, sum
max = sum
END IF
END IF
permute a$
LOOP UNTIL a$ = h$
finds
polska krakow answer
489516 136187 625703
675318 128174 803492
and the final, largest line for part b is
polska krakow
760384 + 894865 = 1655249
|
Posted by Charlie
on 2012-12-13 15:48:57 |