My neighbor has nine kids (all under 21), and their ages are such that you can never pick three kids so that the middle one is the average of the ages of the extreme ones. What are their ages?
(Note that you could also say that you can never find three kids whose ages are in arithmetic progression.)
1 2 6 7 9 14 15 18 20
1 3 6 7 12 14 15 19 20
from
OPEN "ninekids.txt" FOR OUTPUT AS #2
FOR a = 1 TO 12
FOR b = a + 1 TO 13
FOR c = b + 1 TO 14
IF c - b <> b - a THEN
FOR d = c + 1 TO 15
FOR e = d + 1 TO 16
FOR f = e + 1 TO 17
FOR g = f + 1 TO 18
FOR h = g + 1 TO 19
FOR i = h + 1 TO 20
REDIM tk(21)
tk(a) = 1
tk(b) = 1
tk(c) = 1
tk(d) = 1
tk(e) = 1
tk(f) = 1
tk(g) = 1
tk(h) = 1
tk(i) = 1
good = 1
FOR diff = 1 TO 11
FOR st = 1 TO 21 - 2 * diff
IF tk(st) + tk(st + diff) + tk(st + diff * 2) = 3 THEN good = 0: EXIT FOR
NEXT
IF good = 0 THEN EXIT FOR
NEXT
IF good THEN PRINT #2, a; b; c; d; e; f; g; h; i
NEXT
NEXT
NEXT
NEXT
NEXT
NEXT d
END IF
NEXT c
NEXT b
NEXT a
CLOSE
|
Posted by Charlie
on 2004-09-09 09:01:05 |