(In reply to
re: computer exploration -- oh, I see a mistake in my reasoning by Charlie)
I also mistakenly disallowed the digit zero from the addends.
Now I find ten solutions (rather than brian's stated 9):
pie end dry total
241 109 967 1317
241 157 739 1137
263 347 701 1311
269 941 107 1317
281 107 743 1131
421 157 739 1317
521 107 743 1371
641 173 359 1173
683 347 701 1731
821 167 743 1731
The revised program:
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 = 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 = 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$) 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 = 0
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
' check tot composite:
comp = 0
IF tot MOD 3 = 0 OR tot MOD 5 = 0 OR tot MOD 7 = 0 THEN comp = 1
FOR i = 1 TO 21
IF tot MOD prime2(i) = 0 THEN comp = 1
NEXT
IF comp = 0 THEN good = 0
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
|
Posted by Charlie
on 2010-10-07 13:43:44 |