1 2 3 4 5 6 7 8 9 = 100
Insert only THREE arithmetical operators between the digits on the left, so an equality follows.
For example, you could try 123x456+78/9... but somehow it doesn't work!
123 - 45 - 67 + 89
from
DEFDBL A-Z
s$ = "123456789"
ops$ = "*/+-"
FOR p1 = 1 TO 6
FOR p2 = p1 + 1 TO 7
FOR p3 = p2 + 1 TO 8
n1 = VAL(MID$(s$, 1, p1))
n2 = VAL(MID$(s$, p1 + 1, p2 - p1))
n3 = VAL(MID$(s$, p2 + 1, p3 - p2))
n4 = VAL(MID$(s$, p3 + 1, 9 - p3))
FOR op1 = 1 TO 4
FOR op2 = 1 TO 4
FOR op3 = 1 TO 4
op(1) = op1
op(2) = op2
op(3) = op3
n(1) = n1
n(2) = n2
n(3) = n3
n(4) = n4
FOR i = 1 TO 3
IF op(i) = 1 OR op(i) = 2 THEN
IF op(i) = 1 THEN
n(i + 1) = n(i + 1) * n(i)
ELSE
n(i + 1) = n(i) / n(i + 1)
END IF
op(i) = 0
n(i) = 0
END IF
NEXT i
FOR i = 1 TO 3
IF op(i) = 3 OR op(i) = 4 THEN
j = i + 1
DO WHILE j < 3 AND op(j) = 0
j = j + 1
LOOP
IF op(i) = 3 THEN
n(j) = n(j) + n(i)
ELSE
n(j) = n(i) - n(j)
END IF
op(i) = 0
n(i) = 0
END IF
NEXT i
t = n(4)
IF ABS(t - 100) < 1E-12 THEN
PRINT n1; MID$(ops$, op1, 1);
PRINT n2; MID$(ops$, op2, 1);
PRINT n3; MID$(ops$, op3, 1);
PRINT n4
END IF
NEXT
NEXT
NEXT
NEXT
NEXT
NEXT
|
Posted by Charlie
on 2004-07-10 13:38:52 |