Find nine different integers from 1 to 20 inclusive such that no combination of any three of the nine integers form an arithmetic sequence.
(For example, if two of the integers chosen were 7 and 13, then that would preclude 1, 10 and 19 from being included.)
DECLARE SUB addOn (sb!)
CLEAR , , 25000
DIM SHARED num(9)
CLS
FOR st = 1 TO 10
num(1) = st
addOn 2
NEXT st
SUB addOn (sb)
IF sb = 1 THEN strt = 1 ELSE strt = num(sb - 1) + 1
FOR newnum = strt TO 20
good = 1
FOR i = 1 TO sb - 2
FOR j = i + 1 TO sb - 1
IF num(j) - num(i) = newnum - num(j) THEN good = 0: EXIT FOR
NEXT
NEXT
IF good THEN
num(sb) = newnum
IF sb = 9 THEN
FOR i = 1 TO 9
PRINT USING "###"; num(i);
NEXT
PRINT
ELSE
addOn sb + 1
END IF
END IF
NEXT
END SUB
finds
1 2 6 7 9 14 15 18 20
1 3 6 7 12 14 15 19 20
The latter solution of course represents intervals starting with the last interval of the first solution, and so forth.
|
Posted by Charlie
on 2013-04-08 16:03:25 |