In the following alphametic multiplication puzzle, each of the small letters denotes a different base ten digit from 0 to 9. However, each asterisk represents a base ten digit from 0 to 9, whether same or different. None of the numbers can contain any leading zero.
* * *
* * *
-------
* * *
s o *
* * *
--------------
s i m p l e
--------------
What is the number represented by "simple"?
199
515
-------
995
199
995
-------
102485
The program didn't check to assure that the o was different from the remaining letters, but only one solution came out anyway and it fit that requirement also.
FOR a = 100 TO 999
FOR b = 100 TO 999
simple = a * b
IF simple >= 102345 AND simple <= 987654 THEN
s$ = LTRIM$(STR$(simple))
good = 1
FOR i = 1 TO 5
IF INSTR(MID$(s$, i + 1), MID$(s$, i, 1)) > 0 THEN good = 0: EXIT FOR
NEXT
IF good THEN
b1 = b \ 100
b2 = (b \ 10) MOD 10
b3 = b MOD 10
i1 = b3 * a
IF i1 >= 100 AND i1 <= 999 THEN
i2 = b2 * a
IF i2 >= 100 AND i2 <= 999 THEN
i3 = b1 * a
IF i3 >= 100 AND i3 <= 999 THEN
IF simple \ 100000 = i2 \ 100 THEN
PRINT a: PRINT b: PRINT i1: PRINT i2: PRINT i3: PRINT simple: PRINT
END IF
END IF
END IF
END IF
END IF
END IF
NEXT
NEXT
|
Posted by Charlie
on 2010-02-07 14:37:39 |