In the multiplication below, each digit from 0-9 appears exactly 2 times. Decode the multiplication.
* * *
* * *
-------
* * *
* * *
* * *
---------
* * * * *
Note1: No leading zeros in any number.
Note2: For a long time, mathematicians thought that this problem could only be solved using a computer. A few years ago, it was solved analytically, but its solution itīs far from being simple (and short). So, welcome computers.
CLS
FOR a = 1 TO 9
taken(a) = 1
FOR b = 0 TO 9
IF taken(b) < 2 THEN
taken(b) = taken(b) + 1
FOR c = 0 TO 9
IF taken(c) < 2 THEN
taken(c) = taken(c) + 1
n1 = 100 * a + 10 * b + c
FOR f = 1 TO 9
IF taken(f) < 2 THEN
taken(f) = taken(f) + 1
s1 = n1 * f
IF s1 >= 100 AND s1 <= 999 THEN
ss1$ = LTRIM$(STR$(s1))
good = 1
FOR i = 1 TO 3
v = VAL(MID$(ss1$, i, 1))
taken(v) = taken(v) + 1
IF taken(v) > 2 THEN good = 0
NEXT i
IF good THEN
FOR e = 1 TO 9
IF taken(e) < 2 THEN
taken(e) = taken(e) + 1
s2 = n1 * e
IF s2 >= 100 AND s2 <= 999 THEN
ss2$ = LTRIM$(STR$(s2))
good = 1
FOR i = 1 TO 3
v = VAL(MID$(ss2$, i, 1))
taken(v) = taken(v) + 1
IF taken(v) > 2 THEN good = 0
NEXT i
IF good THEN
FOR d = 1 TO 9
IF taken(d) < 2 THEN
taken(d) = taken(d) + 1
s3 = n1 * d
IF s3 >= 100 AND s3 <= 999 THEN
ss3$ = LTRIM$(STR$(s3))
good = 1
FOR i = 1 TO 3
v = VAL(MID$(ss3$, i, 1))
taken(v) = taken(v) + 1
IF taken(v) > 2 THEN good = 0
NEXT i
IF good THEN
prod = 100 * s3 + 10 * s2 + s1
p$ = LTRIM$(STR$(prod))
IF LEN(p$) = 5 THEN
good = 1
FOR i = 1 TO 5
v = VAL(MID$(p$, i, 1))
taken(v) = taken(v) + 1
IF taken(v) > 2 THEN good = 0
NEXT i
IF good THEN
n2 = 100 * d + 10 * e + f
PRINT " "; n1: PRINT " "; n2
PRINT " ----"
PRINT " "; s1: PRINT " "; s2: PRINT " "; s3
PRINT " -----"
PRINT " "; prod
END IF
FOR i = 1 TO 5
v = VAL(MID$(p$, i, 1))
taken(v) = taken(v) - 1
IF taken(v) > 2 THEN good = 0
NEXT i
END IF
END IF
FOR i = 1 TO 3
v = VAL(MID$(ss3$, i, 1))
taken(v) = taken(v) - 1
NEXT i
END IF
taken(d) = taken(d) - 1
END IF
NEXT d
END IF
FOR i = 1 TO 3
v = VAL(MID$(ss2$, i, 1))
taken(v) = taken(v) - 1
NEXT i
END IF
taken(e) = taken(e) - 1
END IF
NEXT e
END IF
FOR i = 1 TO 3
v = VAL(MID$(ss1$, i, 1))
taken(v) = taken(v) - 1
NEXT i
END IF
taken(f) = taken(f) - 1
END IF
NEXT f
taken(c) = taken(c) - 1
END IF
NEXT c
taken(b) = taken(b) - 1
END IF
NEXT b
taken(a) = 0
NEXT
finds
179
224
----
716
358
358
-----
40096
|
Posted by Charlie
on 2008-11-09 19:49:36 |