Mr. X and Mr. Y live in the same avenue with only 9 houses between them. The number on their houses were both prime, and Mr. X found that he could express the number of his house as the sum of the squares of the digits of Mr. y's house number.
What were their house numbers ?
At first thought, with 9 houses between the two, Mr. Y's would be the 10th house over from Mr.X's on the same side of the street. That would imply their house numbers differed by 20 in the usual odd/even numbering system. However a search via computer program found no solution for primes differing by 20.
Then, assuming that the house numbers differ by 10, the program listed below finds two pairs of house numbers that work: x at 13, y at 23 or x at 73, y at 83.
The program is written in UBASIC:
10 P=1
20 while 1=1
30 P=nxtprm(P):P2=P+10
40 if nxtprm(P21)=P2 then
50 :DigSum=0:T=P2
60 :while T>0
70 :Dig=T@10:T=T\10
80 :DigSum=DigSum+Dig*Dig
90 :wend
100 :if P=DigSum then print P,P2:endif
150 :DigSum=0:T=P
160 :while T>0
170 :Dig=T@10:T=T\10
180 :DigSum=DigSum+Dig*Dig
190 :wend
200 :if P2=DigSum then print P,P2:endif
210 wend

When the program was run with p2=p+20 instead of p2=p2+10, there were no results found. The program is manually stopped, and p in the millions when stopped.

Posted by Charlie
on 20031202 10:36:36 