Let us place at random the digits from 1 to 9 into the cells of 3x3 square.
What is the probability of getting a configuration such that the 8 sums (3 rows, 3 columns and 2 main diagonals) will be represented by 8 distinct numbers?
Construct at least one such square.
Extra challenge:
Same two tasks for 4x4 square , numbers 1 to 16 and 10 distinct sums.
DEFDBL A-Z
DECLARE SUB permute (a$)
CLS
a$ = "123456789": h$ = a$
DO
a = VAL(MID$(a$, 1, 1))
b = VAL(MID$(a$, 2, 1))
c = VAL(MID$(a$, 3, 1))
d = VAL(MID$(a$, 4, 1))
e = VAL(MID$(a$, 5, 1))
f = VAL(MID$(a$, 6, 1))
g = VAL(MID$(a$, 7, 1))
h = VAL(MID$(a$, 8, 1))
i = VAL(MID$(a$, 9, 1))
n(1) = a + b + c
n(2) = d + e + f
n(3) = g + h + i
n(4) = a + d + g
n(5) = b + e + h
n(6) = c + f + i
n(7) = a + e + i
n(8) = g + e + c
good = 1
FOR i = 1 TO 7
FOR j = i + 1 TO 8
IF n(i) = n(j) THEN good = 0
NEXT
NEXT
IF good THEN
ctGood = ctGood + 1
END IF
ct = ct + 1
permute a$
LOOP UNTIL a$ = h$
PRINT ctGood, ct, ctGood / ct, ct / ctGood
finds
24960 362880 6.878306878306878D-02 14.53846153846154
meaning 24960 of the 362880 possible ways of arranging the 9 digits had all eight totals different, for a probability of approx. 0.06878306878306878 or 1 in 14.53846153846154. The fraction reduces to 13/189.
|
Posted by Charlie
on 2011-07-12 16:29:00 |