Solve this alphametic, where each of the capital letters in bold denotes a different decimal digit from 0 to 9. None of the numbers can contain any leading zero.
3√(HOW)+ 3√(AND) = 3√(WHEN)
The program below finds
two solutions!
HOW 192 736
AND 375 952
WHEN 2187 6715
Using Excel to calculate the sum of the roots of HOW and AND and comparing the root of WHEN there is no difference in the precision of the first instance. In the second instance the sum is:
18.8660
84.... while the root of the WHEN is 18.8660
94...
For the reason of precision I'd have to disregard the second result.
Back to the program. If the two lines mentioned in the middle of the program are comment out I get no result! Why is this? Is the precision of QuickBASIC greater than Excel?
----------------------------------------------------------------------------
This is based on an algorithm posted by Charlie at
A Great Time Waster.----------------------------------------------------------------------------
DIM SHARED used(10)
CLS
OPEN "CUBES.TXT" FOR OUTPUT AS #1
FOR h = 1 TO 9
IF used(h) = 0 THEN
used(h) = 1
FOR a = 1 TO 9
IF used(a) = 0 THEN
used(a) = 1
FOR w = 1 TO 9
IF used(w) = 0 THEN
used(w) = 1
FOR e = 0 TO 9
IF used(e) = 0 THEN
used(e) = 1
FOR d = 0 TO 9
IF used(d) = 0 THEN
used(d) = 1
FOR n = 0 TO 9
IF used(n) = 0 THEN
used(n) = 1
FOR o = 0 TO 9
IF used(o) = 0 THEN
used(o) = 1
x = h * 100 + o * 10 + w
y = a * 100 + n * 10 + d
z = w * 1000 + h * 100 + e * 10 + n
j = x ^ (1 / 3)
k = y ^ (1 / 3)
l = z ^ (1 / 3)
REM ------------------------------------
q = j + k ' REM the next two lines and run.
q = VAL(LTRIM$(LEFT$((STR$(q)), 20)))
l = VAL(LTRIM$(LEFT$((STR$(l)), 20)))
REM ------------------------------------
IF (l = q) THEN
PRINT #1, x; y; z; " "; h; a; w; e; d; n; o
PRINT x; y; z; " "; h; a; w; e; d; n; o
END IF
used(o) = 0
END IF
NEXT
used(n) = 0
END IF
NEXT
used(d) = 0
END IF
NEXT
used(e) = 0
END IF
NEXT
used(w) = 0
END IF
NEXT
used(a) = 0
END IF
NEXT
used(h) = 0
END IF
NEXT
CLOSE 1
Edited on July 30, 2009, 2:02 am
|
Posted by brianjn
on 2009-07-30 01:44:40 |