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.
Monte Carlo simulation of 4x4 probability:
DEFDBL A-Z
DECLARE SUB permute (a$)
CLS
a0$ = "123456789abcdefg": h$ = a$
DO
src$ = a0$: a$ = ""
FOR ii = 1 TO 16
r = INT(RND(1) * LEN(src$) + 1)
a$ = a$ + MID$(src$, r, 1)
src$ = LEFT$(src$, r - 1) + MID$(src$, r + 1)
NEXT
a = INSTR("123456789abcdefg", MID$(a$, 1, 1))
b = INSTR("123456789abcdefg", MID$(a$, 2, 1))
c = INSTR("123456789abcdefg", MID$(a$, 3, 1))
d = INSTR("123456789abcdefg", MID$(a$, 4, 1))
e = INSTR("123456789abcdefg", MID$(a$, 5, 1))
f = INSTR("123456789abcdefg", MID$(a$, 6, 1))
g = INSTR("123456789abcdefg", MID$(a$, 7, 1))
h = INSTR("123456789abcdefg", MID$(a$, 8, 1))
i = INSTR("123456789abcdefg", MID$(a$, 9, 1))
j = INSTR("123456789abcdefg", MID$(a$, 10, 1))
k = INSTR("123456789abcdefg", MID$(a$, 11, 1))
l = INSTR("123456789abcdefg", MID$(a$, 12, 1))
m = INSTR("123456789abcdefg", MID$(a$, 13, 1))
n = INSTR("123456789abcdefg", MID$(a$, 14, 1))
o = INSTR("123456789abcdefg", MID$(a$, 15, 1))
p = INSTR("123456789abcdefg", MID$(a$, 16, 1))
n(1) = a + b + c + d
n(2) = e + f + g + h
n(3) = i + j + k + l
n(4) = m + n + o + p
n(5) = a + e + i + m
n(6) = b + f + j + n
n(7) = c + g + k + o
n(8) = d + h + l + p
n(9) = a + f + k + p
n(10) = d + g + j + m
good = 1
FOR ii = 1 TO 9
FOR jj = ii + 1 TO 10
IF n(ii) = n(jj) THEN good = 0
NEXT
NEXT
IF good THEN
ctGood = ctGood + 1
END IF
ct = ct + 1
PRINT ctGood; ct, ctGood / ct
LOOP
when stopped after running for a while, the last line of stats was:
461307 2080538 .2217248615502336
which would be consistent with a probability of 2/9, and of course many other possible fractions.
|
Posted by Charlie
on 2011-07-13 12:00:48 |