Place the numbers 1 to 10 around a circle such that the sum of any two adjacent numbers is equal to the sum of the pair of numbers directly opposite. In how many ways can this be done? Can this be done with 1 to 8? With 1 to 6?
DECLARE SUB place ()
DIM SHARED n, nbr
n = 10
DIM SHARED used(n), cir(n), ct
CLS
place
PRINT ct
SUB place
nbr = nbr + 1
IF nbr <= n / 2 + 1 THEN
IF nbr = 1 THEN hi = 1: ELSE hi = n
FOR i = 1 TO hi
IF used(i) = 0 THEN
cir(nbr) = i
used(i) = 1
place
used(i) = 0
END IF
NEXT
ELSE
t = cir(nbr - n / 2) + cir(nbr - 1 - n / 2)
newnum = t - cir(nbr - 1)
IF newnum > 0 AND newnum <= n THEN
IF used(newnum) = 0 THEN
cir(nbr) = newnum
used(newnum) = 1
IF nbr = n THEN
t = cir(1) + cir(n)
t2 = cir(1 + n / 2) + cir(n - n / 2)
IF t = t2 AND cir(2) < cir(n) THEN
FOR i = 1 TO n
PRINT cir(i);
NEXT
PRINT
ct = ct + 1
END IF
ELSE
place
END IF
used(newnum) = 0
END IF
END IF
END IF
nbr = nbr - 1
END SUB
finds the following set of 24 solutions:
1 4 5 8 9 2 3 6 7 10
1 4 5 10 7 2 3 6 9 8
1 4 7 6 9 2 3 8 5 10
1 4 7 10 5 2 3 8 9 6
1 4 9 6 7 2 3 10 5 8
1 4 9 8 5 2 3 10 7 6
1 6 3 8 9 2 5 4 7 10
1 6 3 10 7 2 5 4 9 8
1 6 7 4 9 2 5 8 3 10
1 6 9 4 7 2 5 10 3 8
1 7 3 9 5 6 2 8 4 10
1 7 3 10 4 6 2 8 5 9
1 7 4 8 5 6 2 9 3 10
1 7 4 10 3 6 2 9 5 8
1 7 5 8 4 6 2 10 3 9
1 7 5 9 3 6 2 10 4 8
1 8 2 9 5 6 3 7 4 10
1 8 2 10 4 6 3 7 5 9
1 8 3 6 9 2 7 4 5 10
1 8 4 7 5 6 3 9 2 10
1 8 5 4 9 2 7 6 3 10
1 8 5 7 4 6 3 10 2 9
1 9 2 8 5 6 4 7 3 10
1 9 3 7 5 6 4 8 2 10
All are presented starting at the 1. So as to eliminate reflections, only those with a lower number to the 1's right than to its left (at the end of each list) are shown; there would be 48 solutions if the reverse sequences were counted.
By changing the value of n and rerunning we find two solutions (4 if you count reflections) for n=6:
1 4 5 2 3 6
1 5 3 4 2 6
but none for n = 8.
There are also no solutions for n = 12.
Going to n=14, there are 720 solutions (1440 counting reversals).
|
Posted by Charlie
on 2013-11-26 12:13:40 |