Solve this
alphametic, where each capital letter in bold represents a different decimal digit from 0 to 9. None of the numbers can admit any leading zero.
(
NOW)
THE = (
OLD)
HAT
10 ' nowtheldax <--- string's assumed representation letters (x is not used)
20 D="0123456789"
30 H=D
40 loop
50 Ix=instr(D,"0")
60 if Ix<3 or Ix=4 or Ix=5 then goto *NotThis
70 Now=val(left(D,3))
80 The=val(mid(D,4,3))
90 Old=val(mid(D,2,1)+mid(D,7,2))
100 Hat=val(mid(D,5,1)+mid(D,9,1)+mid(D,4,1))
105 A=The*log(Now):B=Hat*log(Old)
110 if abs(A-B)/B<0.000000001 then print Now;The;Old;Hat
120 *NotThis
130 gosub *Permute(&D)
140 if D=H then goto 9999
150 endloop
9999 end
729^680 = 243^816
(Check: 729 = 3^6 and 243 = 3^5, while 816/680 = 6/5.)
Added: going back to Daniel's comment of Mathematica taking under 10 minutes: the above UBASIC took a minute and a quarter to go through all possibilities. Note also, tolerance had to be allowed in the precision/accuracy when using logarithms, as exact equality shouldn't be expected when representations of transendental numbers are held in finite variable areas.
Edited on February 20, 2009, 12:50 pm
|
Posted by Charlie
on 2009-02-20 12:39:16 |