Solve the following alphametic, given that two are primes and one is a composite:
SEVEN - THREE = FOUR
BONUS: Without the restriction of the number of composites and primes in the alphametic, how many different solutions are there?
10 dim Used(9)
20 for S=1 to 9
30 if Used(S)=0 then
40 :Used(S)=1
50 :for T=1 to 9
60 :if Used(T)=0 then
70 :Used(T)=1
80 :for F=1 to 9
90 :if Used(F)=0 then
100 :Used(F)=1
110 :for E=0 to 9
120 :if Used(E)=0 then
130 :Used(E)=1
140 :for V=0 to 9
150 :if Used(V)=0 then
160 :Used(V)=1
170 :for N=0 to 9
180 :if Used(N)=0 then
190 :Used(N)=1
200 :Seven=10000*S+1010*E+100*V+N
210 :for H=0 to 9
220 :if Used(H)=0 then
230 :Used(H)=1
240 :for R=0 to 9
250 :if Used(R)=0 then
260 :Used(R)=1
270 :Three=10000*T+1000*H+100*R+11*E
280 :for O=0 to 9
290 :if Used(O)=0 then
300 :Used(O)=1
310 :for U=0 to 9
320 :if Used(U)=0 then
330 :Used(U)=1
340 :Four=1000*F+100*O+10*U+R
350 :if Seven-Three=Four then
355 :inc Sct
360 :print Seven;Three;Four,
370 :PCt=0
380 :if prmdiv(Seven)=Seven then inc PCt:Plst="7":else Plst="":endif
390 :if prmdiv(Three)=Three then inc PCt:Plst=Plst+"3":endif
400 :if prmdiv(Four)=Four then inc PCt:Plst=Plst+"4":endif
403 :print PCt,Plst
410 :endif
420 :Used(U)=0
430 :endif
440 :next
450 :Used(O)=0
460 :endif
470 :next
480 :Used(R)=0
490 :endif
500 :next
510 :Used(H)=0
520 :endif
530 :next
540 :Used(N)=0
550 :endif
560 :next
570 :Used(V)=0
580 :endif
590 :next
600 :Used(E)=0
610 :endif
620 :next
630 :Used(F)=0
640 :endif
650 :next
660 :Used(T)=0
670 :endif
680 :next
690 :Used(S)=0
700 :endif
710 next
720 print Sct
finds
23439 17633 5806 0
23938 17533 6405 0
24349 17544 6805 0
25758 19355 6403 0
23439 15633 7806 0
23938 16533 7405 0
24349 16544 7805 0
25758 16355 9403 1 4
31519 26811 4708 0
31519 24811 6708 0
35159 28455 6704 1 7
36061 28566 7495 1 7
35159 26455 8704 1 7
36061 27566 8495 1 7
41517 38611 2906 1 3
41918 36711 5207 0
41918 35711 6207 0
45157 38255 6902 0
41517 32611 8906 1 3
45157 36255 8902 0
52728 49622 3106 0
56368 49266 7102 0
52728 43622 9106 0
56368 47266 9102 0
61219 57811 3408 0
62129 58722 3407 2 74
61219 53811 7408 0
62129 53722 8407 1 7
71315 68411 2904 0
71814 69311 2503 1 4
73135 68233 4902 0
71315 62411 8904 0
73135 64233 8902 0
71814 62311 9503 1 3
82526 79422 3104 0
84346 79244 5102 0
82526 73422 9104 0
84346 75244 9102 0
38
Indicating and listing 38 solutions when ignoring composites vs primes.
The first number following each solution is the number of those numbers that are prime. In most cases none is prime; in a few cases one of the numbers is prime, but in only one case are two of the numbers prime: 62129 - 58722 = 3407.
The remaining digits on the lines with primes are shorthand for which of the three numbers is/are prime. In the case of the solution with two primes this is 74, indicating SEVEN and FOUR represent primes: 62129 and 3407.
|
Posted by Charlie
on 2011-09-18 17:01:49 |