1. Different integers A, B, C, D consist of the same digits. A+B=C. B+C=D. What are the smallest numbers which satisfy this?
2. Can it also be solved if we add C+D=E?
3. What if instead we add A+D=E?
DEFDBL A-Z
CLS
FOR c = 2 TO 999
FOR a = 1 TO c / 2
b = c - a
d = b + c
as$ = LTRIM$(STR$(a))
ds$ = LTRIM$(STR$(d))
good = 1
FOR i = 1 TO LEN(ds$)
ix = INSTR(as$, MID$(ds$, i, 1))
IF ix = 0 THEN good = 0: EXIT FOR
as$ = LEFT$(as$, ix - 1) + MID$(as$, ix + 1)
NEXT
IF good THEN
PRINT a; b; c; d
EXIT FOR
END IF
NEXT a
IF good THEN EXIT FOR
NEXT c
FOR c = 2 TO 9999
FOR a = 1 TO c / 2
b = c - a
d = b + c
as$ = LTRIM$(STR$(a))
ds$ = LTRIM$(STR$(d))
good = 1
FOR i = 1 TO LEN(ds$)
ix = INSTR(as$, MID$(ds$, i, 1))
IF ix = 0 THEN good = 0: EXIT FOR
as$ = LEFT$(as$, ix - 1) + MID$(as$, ix + 1)
NEXT
IF good THEN
e = c + d
bs$ = LTRIM$(STR$(b))
es$ = LTRIM$(STR$(e))
FOR i = 1 TO LEN(es$)
ix = INSTR(bs$, MID$(es$, i, 1))
IF ix = 0 THEN good = 0: EXIT FOR
bs$ = LEFT$(bs$, ix - 1) + MID$(bs$, ix + 1)
NEXT
IF good THEN
PRINT a; b; c; d; e
EXIT FOR
END IF
END IF
NEXT a
IF good THEN EXIT FOR
NEXT c
FOR c = 2 TO 9999
FOR a = 1 TO c / 2
b = c - a
d = b + c
as$ = LTRIM$(STR$(a))
ds$ = LTRIM$(STR$(d))
good = 1
FOR i = 1 TO LEN(ds$)
ix = INSTR(as$, MID$(ds$, i, 1))
IF ix = 0 THEN good = 0: EXIT FOR
as$ = LEFT$(as$, ix - 1) + MID$(as$, ix + 1)
NEXT
IF good THEN
e = c + d
bc$ = LTRIM$(STR$(b)) + LTRIM$(STR$(c))
de$ = ds$ + LTRIM$(STR$(e))
FOR i = 1 TO LEN(de$)
ix = INSTR(bc$, MID$(de$, i, 1))
IF ix = 0 THEN good = 0: EXIT FOR
bc$ = LEFT$(bc$, ix - 1) + MID$(bc$, ix + 1)
NEXT
IF good THEN
PRINT a; b; c; d; e
EXIT FOR
END IF
END IF
NEXT a
IF good THEN EXIT FOR
NEXT c
Finds the three answers:
A B C D E
15 18 33 51
1458 1845 3303 5148 8451
1242 1440 2682 4122 6804
|
Posted by Charlie
on 2013-11-12 18:52:56 |