There are 51 solutions to the alphametic using primes:
pie end dry total
127 769 953 1849
127 769 983 1879
157 769 983 1909
163 359 947 1469
163 389 947 1499
257 719 983 1959
257 739 941 1937
257 769 941 1967
257 769 983 2009
263 347 719 1329
263 347 751 1361
263 349 971 1583
263 359 941 1563
263 359 947 1569
263 359 971 1593
263 379 941 1583
263 389 941 1593
263 389 947 1599
263 389 971 1623
263 397 751 1411
283 317 769 1369
283 347 719 1349
283 347 751 1381
283 347 761 1391
283 347 769 1399
283 349 967 1599
283 349 971 1603
283 359 941 1583
283 359 947 1589
283 359 967 1609
283 359 971 1613
283 367 719 1369
283 367 751 1401
283 379 941 1603
283 397 751 1431
283 397 761 1441
293 347 751 1391
293 347 761 1401
293 367 751 1411
457 719 983 2159
457 769 983 2209
467 719 953 2139
467 719 983 2169
487 719 953 2159
487 769 953 2209
547 719 983 2249
547 769 983 2299
587 739 941 2267
587 769 941 2297
647 719 953 2319
647 719 983 2349
The totals have not been tested for prime vs composite, but none seem to fit the criterion that all pairs of its digits form a 2-digit prime. Any total that has an even number (including zero) fails. Any that has two matching digits other than 1 fails. Any that has both a 3 and a 9 fails, or a 1 and a 5 for that matter.
DECLARE FUNCTION nodup! (x$)
DATA 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179
DATA 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269
DATA 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367
DATA 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461
DATA 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571
DATA 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661
DATA 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773
DATA 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883
DATA 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997
DATA 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71
DATA 73 , 79 , 83 , 89 , 97
DIM prime(143), prime2(21)
FOR i = 1 TO 143: READ prime(i): PRINT prime(i); : NEXT
PRINT
FOR i = 1 TO 21: READ prime2(i): PRINT prime2(i); : NEXT
PRINT : PRINT
FOR p1 = 1 TO 141
pie = prime(p1): pie$ = LTRIM$(STR$(pie))
chk1$ = LEFT$(pie$, 2)
IF nodup(pie$) THEN
FOR p2 = p1 + 1 TO 142
end0 = prime(p2): end0$ = LTRIM$(STR$(end0))
IF RIGHT$(pie$, 1) = LEFT$(end0$, 1) AND nodup(chk1$ + end0$) THEN
chk2$ = chk1$ + LEFT$(end0$, 2)
FOR p3 = p2 + 1 TO 143
dry = prime(p3): dry$ = LTRIM$(STR$(dry))
IF RIGHT$(end0$, 1) = LEFT$(dry$, 1) AND nodup(chk2$ + dry$) THEN
chk3$ = chk2$ + dry$
IF nodup(chk3$ + "0") THEN
tot = pie + end0 + dry
IF tot > 999 AND tot < 10000 THEN
t$ = LTRIM$(STR$(tot))
good = 1
FOR i = 1 TO 4
FOR j = 1 TO 4
IF i <> j THEN
ptest = VAL(MID$(t$, i, 1) + MID$(t$, j, 1))
foundp = 1
FOR k = 1 TO 21
' IF ptest = prime2(k) THEN foundp = 1: EXIT FOR
NEXT
IF foundp = 0 THEN good = 0: EXIT FOR
END IF
NEXT j
IF good = 0 THEN EXIT FOR
NEXT i
IF good THEN
PRINT pie; end0; dry, tot
ct = ct + 1: IF ct MOD 40 = 0 THEN DO: LOOP UNTIL INKEY$ > "": PRINT
END IF
END IF
END IF
END IF
NEXT p3
END IF
NEXT p2
END IF
NEXT p1
PRINT ct
FUNCTION nodup (x$)
nd = -1
FOR i = 1 TO LEN(x$) - 1
IF INSTR(MID$(x$, i + 1), MID$(x$, i, 1)) THEN nd = 0: EXIT FOR
NEXT
nodup = nd
END FUNCTION
Note the commenting out of the tests for primality of the pairs so that the candidates could be listed.
|
Posted by Charlie
on 2010-10-07 13:27:55 |