When this was in the queue, I somehow neglected to see the part about the reverse directions.
However, for the problem as given, the following program looks for primes in both directions for a given row, column or diagonal. It doesn't check that the sum of the digits in that number is also prime, but the found solutions all meet that criterion.
10 dim G(3,3)
15 open "primal.txt" for output as #2
20 gosub *Place(1,1):print Ct
30 end
110 *Place(R,C)
120 G(R,C)=2:gosub *TryIt
130 G(R,C)=3:gosub *TryIt
140 G(R,C)=5:gosub *TryIt
150 G(R,C)=7:gosub *TryIt
160 return
210 *TryIt
220 if R=3 and C=3 then
221 :R1=100*G(1,1)+10*G(1,2)+G(1,3)
222 :R2=100*G(2,1)+10*G(2,2)+G(2,3)
223 :R3=100*G(3,1)+10*G(3,2)+G(3,3)
224 :C1=100*G(1,1)+10*G(2,1)+G(3,1)
225 :C2=100*G(1,2)+10*G(2,2)+G(3,2)
226 :C3=100*G(1,3)+10*G(2,3)+G(3,3)
227 :D1=100*G(1,1)+10*G(2,2)+G(3,3)
228 :D2=100*G(3,1)+10*G(2,2)+G(1,3)
230 :R1a=100*G(1,3)+10*G(1,2)+G(1,1)
231 :R2a=100*G(2,3)+10*G(2,2)+G(2,1)
232 :R3a=100*G(3,3)+10*G(3,2)+G(3,1)
233 :C1a=100*G(3,1)+10*G(2,1)+G(1,1)
234 :C2a=100*G(3,2)+10*G(2,2)+G(1,2)
235 :C3a=100*G(3,3)+10*G(2,3)+G(1,3)
236 :D1a=100*G(3,3)+10*G(2,2)+G(1,1)
237 :D2a=100*G(1,3)+10*G(2,2)+G(3,1)
240 :if R1=prmdiv(R1) and R2=prmdiv(R2) and R3=prmdiv(R3) and C1=prmdiv(C1) and C2=prmdiv(C2) and C3=prmdiv(C3) and D1=prmdiv(D1) and D2=prmdiv(D2) then
241 :if R1a=prmdiv(R1a) and R2a=prmdiv(R2a) and R3a=prmdiv(R3a) and C1a=prmdiv(C1a) and C2a=prmdiv(C2a) and C3a=prmdiv(C3a) and D1a=prmdiv(D1a) and D2a=prmdiv(D2a) then
245 :for Row=1 to 3:for Col=1 to 3:print G(Row,Col);:next:print:next
246 :for Row=1 to 3:for Col=1 to 3:print #2,G(Row,Col);:next:print #2,:next
250 :print:print:Ct=Ct+1
251 :print #2,:print #2,
254 :endif
255 :endif
300 :else
310 :Col=C+1:Row=R:if Col>3 then Col=1:Row=R+1:endif
320 :gosub *Place(Row,Col)
330 return
finds only
3 3 7
3 5 3
7 3 3
3 7 3
7 5 7
3 7 3
7 3 3
3 5 3
3 3 7
but the last is a rotation of the first, and because of symmetry is also a left-right reflection of the first about a vertical axis (or about a horizontal axis). But since these are the only three found, I don't see how there can be a third that is not such a rotation/reflection.
Edited on December 1, 2008, 4:43 pm
|
Posted by Charlie
on 2008-12-01 16:40:58 |