You need to make it so that the sum in every row and column will be equal. To do that, you need to select two positive integers. The only numbers that you can place in the grid are those two integers, their sum, their difference, their product, or their quotient. You can place only whole numbers.
Can you complete the grid?
(In reply to
The integers by Assaf)
With the integers 3 and 12 (and the resulting 15, 9, 36 and 4), there are 4942 solutions where each row and column adds to 86. A sampling follows:
3 3 12 4 15 49 3 3 12 4 15 49 3 3 12 15 4 49 3 3 15 12 4 49
15 9 17 15 15 15 36 12 17 9 9 3 36 12 17 9 9 3 15 12 17 12 15 15
24 4 15 36 4 3 24 4 3 36 15 4 24 4 3 36 15 4 24 4 15 4 36 3
36 15 15 9 7 4 4 12 36 15 7 12 15 12 36 4 7 12 4 12 15 36 7 12
4 43 15 12 9 3 15 43 9 12 4 3 4 43 9 12 15 3 4 43 12 12 12 3
4 12 12 10 36 12 4 12 9 10 36 15 4 12 9 10 36 15 36 12 12 10 12 4
3 4 3 12 15 49 3 4 3 12 15 49 3 4 3 12 15 49 3 4 3 12 15 49
15 3 17 12 36 3 36 9 17 9 12 3 36 9 17 9 12 3 36 9 17 12 9 3
24 9 36 4 9 4 24 3 15 4 36 4 24 3 36 15 4 4 24 3 15 36 4 4
4 15 9 36 7 15 4 15 12 36 7 12 4 15 12 36 7 12 15 15 36 4 7 9
4 43 9 12 15 3 4 43 3 15 12 9 15 43 9 4 12 3 4 43 3 12 15 9
36 12 12 10 4 12 15 12 36 10 4 9 4 12 9 10 36 15 4 12 12 10 36 12
3 4 3 15 12 49 3 4 9 9 12 49 3 9 9 4 12 49 3 9 9 4 12 49
36 3 17 12 15 3 36 3 17 15 12 3 15 3 17 12 36 3 36 3 17 15 12 3
24 9 36 9 4 4 24 9 9 4 36 4 24 15 3 36 4 4 24 4 3 36 15 4
4 15 12 36 7 12 4 15 12 36 7 12 4 12 36 15 7 12 4 12 36 12 7 15
15 43 3 4 12 9 4 43 3 12 15 9 4 43 9 9 12 9 15 43 12 9 4 3
4 12 15 10 36 9 15 12 36 10 4 9 36 4 12 10 15 9 4 15 9 10 36 12
3 9 9 12 4 49 3 9 9 12 4 49 3 9 12 4 9 49 3 9 12 9 4 49
15 3 17 12 36 3 36 3 17 12 9 9 15 12 17 12 15 15 15 3 17 36 12 3
24 4 3 36 15 4 24 4 36 4 15 3 24 4 15 36 4 3 24 15 3 4 36 4
36 15 9 4 7 15 15 12 12 36 7 4 36 9 15 15 7 4 36 4 15 12 7 12
4 43 12 12 12 3 4 43 3 12 15 9 4 43 12 9 15 3 4 43 3 15 12 9
4 12 36 10 12 12 4 15 9 10 36 12 4 9 15 10 36 12 4 12 36 10 15 9
3 12 3 4 15 49 3 12 3 4 15 49 3 12 3 4 15 49 3 12 3 4 15 49
15 3 17 12 36 3 15 3 17 12 36 3 36 3 17 12 15 3 36 3 17 15 12 3
24 4 3 36 15 4 24 9 9 36 4 4 24 4 15 36 4 3 24 4 9 9 36 4
4 15 36 9 7 15 36 4 12 15 7 12 4 15 36 12 7 12 4 12 12 36 7 15
4 43 12 15 9 3 4 43 9 9 12 9 4 43 3 12 9 15 15 43 9 12 4 3
36 9 15 10 4 12 4 15 36 10 12 9 15 9 12 10 36 4 4 12 36 10 12 12
3 12 3 4 15 49 3 12 3 15 4 49 3 12 3 15 4 49 3 12 3 15 4 49
36 3 17 12 15 3 15 3 17 36 12 3 36 9 17 9 12 3 36 3 17 12 15 3
24 15 3 36 4 4 24 9 9 4 36 4 24 4 36 4 15 3 24 9 9 4 36 4
15 4 36 12 7 12 4 15 36 9 7 15 4 9 15 36 7 15 15 4 9 36 7 15
4 43 15 12 9 3 4 43 9 12 15 3 4 43 3 12 12 12 4 43 12 9 15 3
4 9 12 10 36 15 36 4 12 10 12 12 15 9 12 10 36 4 4 15 36 10 9 12
3 12 9 4 9 49 3 12 9 9 4 49 3 15 3 4 12 49 3 15 3 4 12 49
36 3 17 12 15 3 36 3 17 12 15 3 15 3 17 12 36 3 36 9 17 9 12 3
24 4 36 15 4 3 24 4 3 4 36 15 24 4 36 15 4 3 24 3 36 15 4 4
4 15 9 36 7 15 4 15 12 36 7 12 4 12 15 36 7 12 4 12 15 36 7 12
4 43 3 9 15 12 4 43 9 15 12 3 4 43 3 9 12 15 4 43 3 12 15 9
15 9 12 10 36 4 15 9 36 10 12 4 36 9 12 10 15 4 15 4 12 10 36 9
3 15 3 12 4 49 3 15 3 12 4 49 3 15 3 12 4 49 4 3 3 12 15 49
15 3 17 12 36 3 36 3 17 12 15 3 36 9 17 9 12 3 3 12 17 15 36 3
24 9 36 4 9 4 24 4 15 4 36 3 24 3 36 4 15 4 24 4 36 4 15 3
4 12 12 36 7 15 4 12 12 36 7 15 15 4 9 36 7 15 4 12 12 36 7 15
4 43 9 12 15 3 15 43 3 12 9 4 4 43 9 15 12 3 15 43 3 9 4 12
36 4 9 10 15 12 4 9 36 10 15 12 4 12 12 10 36 12 36 12 15 10 9 4
4 3 3 12 15 49 4 3 3 12 15 49 4 3 3 12 15 49 4 3 3 12 15 49
3 15 17 36 12 3 3 12 17 9 36 9 3 12 17 36 9 9 3 15 17 36 12 3
24 4 9 9 36 4 24 4 9 36 4 9 24 4 15 4 36 3 24 4 3 15 36 4
4 12 36 15 7 12 15 12 36 4 7 12 15 12 36 12 7 4 15 9 36 4 7 15
15 43 9 4 12 3 4 43 9 15 12 3 4 43 3 12 15 9 4 43 15 9 12 3
36 9 12 10 4 15 36 12 12 10 12 4 36 12 12 10 4 12 36 12 12 10 4 12
4 3 3 12 15 49 4 3 3 12 15 49 4 3 3 12 15 49 4 3 3 12 15 49
3 12 17 15 36 3 3 15 17 36 12 3 3 12 17 15 36 3 3 15 17 36 12 3
24 9 9 36 4 4 24 4 36 9 4 9 24 4 15 36 4 3 24 4 36 15 4 3
36 15 12 4 7 12 36 12 15 4 7 12 36 12 12 4 7 15 36 12 15 4 7 12
4 43 9 9 12 9 4 43 3 15 12 9 15 43 3 9 12 4 15 43 3 9 12 4
15 4 36 10 12 9 15 9 12 10 36 4 4 12 36 10 12 12 4 9 12 10 36 15
4 3 3 12 15 49 4 3 3 12 15 49 4 3 3 12 15 49 4 3 3 12 15 49
9 12 17 9 36 3 9 9 17 36 12 3 9 12 17 9 36 3 9 9 17 36 12 3
24 4 3 36 4 15 24 4 9 9 36 4 24 9 9 36 4 4 24 15 3 4 36 4
4 12 36 15 7 12 9 15 36 4 7 15 36 15 9 4 7 15 36 4 15 15 7 9
9 43 12 4 15 3 4 43 9 15 12 3 4 43 12 15 9 3 9 43 12 9 4 9
36 12 15 10 9 4 36 12 12 10 4 12 9 4 36 10 15 12 4 12 36 10 12 12
4 3 3 12 15 49 4 3 3 12 15 49 4 3 3 12 15 49 4 3 3 15 12 49
36 9 17 9 12 3 36 12 17 9 9 3 36 9 17 12 9 3 3 15 17 12 36 3
24 4 36 15 4 3 24 4 36 15 4 3 24 4 3 36 15 4 24 4 36 4 15 3
4 15 12 36 7 12 4 9 15 36 7 15 15 15 36 4 7 9 4 12 12 36 7 15
3 43 9 4 12 15 9 43 3 4 15 12 3 43 15 12 4 9 15 43 3 9 12 4
15 12 9 10 36 4 9 15 12 10 36 4 4 12 12 10 36 12 36 9 15 10 4 12
4 3 3 15 12 49 4 3 3 15 12 49 4 3 3 15 12 49 4 3 3 15 12 49
3 12 17 9 36 9 3 12 17 36 15 3 3 15 17 36 12 3 9 9 17 12 36 3
24 15 36 4 4 3 24 4 3 4 36 15 24 4 3 4 36 15 24 4 15 36 4 3
15 4 12 36 7 12 36 15 15 9 7 4 36 12 15 12 7 4 36 15 12 4 7 12
4 43 3 12 15 9 4 43 12 12 12 3 15 43 12 9 4 3 4 43 3 9 12 15
36 9 15 10 12 4 15 9 36 10 4 12 4 9 36 10 15 12 9 12 36 10 15 4
4 3 3 15 12 49 4 3 9 9 12 49 4 3 9 9 12 49 4 3 9 9 12 49
36 9 17 9 12 3 3 15 17 12 36 3 3 15 17 36 12 3 3 15 17 12 36 3
24 15 36 4 4 3 24 4 3 36 15 4 24 4 3 4 36 15 24 4 3 36 4 15
4 12 12 36 7 15 4 9 36 15 7 15 15 9 36 15 7 4 36 12 12 15 7 4
3 43 9 12 15 4 15 43 9 4 12 3 4 43 9 12 15 3 15 43 9 4 12 3
15 4 9 10 36 12 36 12 12 10 4 12 36 12 12 10 4 12 4 9 36 10 15 12
4 3 9 9 12 49 4 3 9 12 9 49 4 3 9 12 9 49 4 3 12 9 9 49
9 9 17 12 36 3 3 12 17 36 15 3 9 12 17 9 36 3 3 12 17 36 15 3
24 15 3 36 4 4 24 4 3 15 36 4 24 4 3 36 15 4 24 9 36 4 4 9
36 4 12 15 7 12 15 12 36 4 7 12 4 12 36 15 7 12 36 15 9 15 7 4
9 43 9 4 12 9 4 43 12 9 15 3 9 43 12 4 15 3 4 43 3 12 15 9
4 12 36 10 15 9 36 12 9 10 4 15 36 12 9 10 4 15 15 4 9 10 36 12
4 9 3 9 12 49 4 9 3 9 12 49 4 9 3 9 12 49 4 9 3 9 12 49
3 15 17 36 12 3 3 12 17 36 15 3 3 3 17 36 12 15 9 9 17 12 36 3
24 3 15 4 36 4 24 9 9 4 36 4 24 4 36 4 15 3 24 4 3 36 15 4
4 12 36 15 7 12 15 4 36 12 7 12 36 15 9 15 7 4 4 12 36 15 7 12
15 43 3 12 4 9 4 43 9 15 12 3 15 43 9 12 4 3 9 43 15 4 12 3
36 4 12 10 15 9 36 9 12 10 4 15 4 12 12 10 36 12 36 9 12 10 4 15
4 9 3 9 12 49 4 9 3 9 12 49 4 9 3 9 12 49 4 9 3 9 12 49
9 3 17 36 12 9 15 3 17 12 36 3 36 3 17 12 15 3 36 3 17 15 12 3
24 4 36 4 15 3 24 15 36 4 4 3 24 4 9 36 4 9 24 4 3 36 15 4
36 15 12 12 7 4 4 12 12 36 7 15 4 12 36 15 7 12 15 12 36 4 7 12
9 43 3 15 4 12 3 43 9 15 12 4 9 43 9 4 12 9 3 43 15 12 4 9
4 12 15 10 36 9 36 4 9 10 15 12 9 15 12 10 36 4 4 15 12 10 36 9
4 9 3 12 9 49 4 9 3 12 9 49 4 9 3 12 9 49 4 9 3 12 9 49
3 12 17 15 36 3 3 3 17 36 15 12 9 3 17 12 36 9 36 3 17 12 15 3
24 3 15 36 4 4 24 4 36 4 15 3 24 4 3 36 15 4 24 4 3 36 15 4
15 15 36 4 7 9 36 15 9 15 7 4 36 15 12 4 7 12 15 15 36 4 7 9
4 43 3 9 15 12 15 43 12 9 4 3 9 43 15 12 4 3 3 43 12 12 4 12
36 4 12 10 15 9 4 12 9 10 36 15 4 12 36 10 15 9 4 12 15 10 36 9
4 12 3 9 9 49 4 12 3 9 9 49 4 12 3 9 9 49 9 3 9 4 12 49
3 3 17 36 15 12 15 3 17 12 36 3 36 3 17 12 15 3 9 9 17 12 36 3
24 15 36 4 4 3 24 9 9 36 4 4 24 9 9 36 4 4 24 15 3 36 4 4
36 9 15 15 7 4 4 15 36 15 7 9 15 4 36 15 7 9 36 4 12 15 7 12
4 43 3 12 15 9 3 43 9 4 15 12 3 43 12 4 15 9 4 43 9 9 12 9
15 4 12 10 36 9 36 4 12 10 15 9 4 15 9 10 36 12 4 12 36 10 15 9
9 3 9 12 4 49 9 3 9 12 4 49 9 3 12 9 4 49 9 4 3 9 12 49
9 12 17 36 9 3 36 9 17 9 12 3 9 15 17 15 15 15 9 9 17 36 12 3
24 4 9 4 36 9 24 4 36 4 15 3 24 4 15 4 36 3 24 3 36 4 4 15
4 15 36 12 7 12 4 15 12 36 7 12 4 12 15 36 7 12 36 12 12 15 7 4
4 43 3 12 15 9 9 43 3 15 12 4 4 43 12 12 12 3 4 43 9 12 15 3
36 9 12 10 15 4 4 12 9 10 36 15 36 9 15 10 12 4 4 15 9 10 36 12
9 4 3 12 9 49 9 9 3 4 12 49 9 9 3 4 12 49 9 9 3 4 12 49
9 9 17 12 36 3 9 9 17 12 36 3 9 3 17 36 12 9 36 3 17 15 12 3
24 3 36 4 4 15 24 4 3 36 15 4 24 4 36 9 4 9 24 4 36 9 4 9
4 15 12 36 7 12 4 9 36 15 7 15 36 12 12 15 7 4 4 15 12 36 7 12
4 43 9 12 15 3 4 43 15 9 12 3 4 43 9 12 15 3 4 43 3 12 15 9
36 12 9 10 15 4 36 12 12 10 4 12 4 15 9 10 36 12 9 12 15 10 36 4
9 9 3 4 12 49 9 9 3 12 4 49 9 9 3 12 4 49 9 9 3 12 4 49
36 9 17 9 12 3 9 3 17 36 9 12 9 12 17 36 9 3 36 3 17 12 9 9
24 9 9 36 4 4 24 4 36 4 15 3 24 3 36 4 15 4 24 4 36 4 15 3
9 4 36 15 7 15 36 12 15 12 7 4 36 4 15 15 7 9 4 15 12 36 7 12
4 43 9 12 15 3 4 43 3 12 15 9 4 43 3 9 15 12 9 43 3 12 15 4
4 12 12 10 36 12 4 15 12 10 36 9 4 15 12 10 36 9 4 12 15 10 36 9
9 12 3 4 9 49 9 12 3 4 9 49 9 12 3 9 4 49 9 12 3 9 4 49
9 3 17 9 36 12 36 3 17 12 15 3 9 3 17 36 12 9 36 3 17 12 15 3
24 4 9 36 4 9 24 4 3 36 15 4 24 4 15 4 36 3 24 4 3 36 15 4
4 15 36 15 7 9 4 15 36 15 7 9 36 12 12 15 7 4 4 12 36 15 7 12
4 43 9 12 15 3 9 43 12 9 4 9 4 43 3 12 15 9 9 43 12 4 9 9
36 9 12 10 15 4 4 9 15 10 36 12 4 12 36 10 12 12 4 12 15 10 36 9
15 3 3 4 12 49 15 3 3 4 12 49 15 3 3 4 12 49 15 3 3 12 4 49
3 12 17 9 36 9 3 15 17 12 36 3 3 12 17 36 15 3 3 9 17 36 12 9
24 4 3 36 15 4 24 4 36 15 4 3 24 4 36 9 4 9 24 15 3 4 36 4
4 15 36 15 7 9 4 12 15 36 7 12 36 15 12 12 7 4 4 12 36 15 7 12
4 43 12 12 12 3 4 43 3 9 12 15 4 43 3 15 12 9 4 43 15 9 12 3
36 9 15 10 4 12 36 9 12 10 15 4 4 9 15 10 36 12 36 4 12 10 15 9
None were magic in the sense of the diagonals also adding to 86.
DECLARE SUB fillIn (intr!)
CLEAR , , 9999
OPEN "placnum3.txt" FOR OUTPUT AS #2
DIM SHARED grid(6, 6), avail(6, 200, 5), excl(6)
OPEN "placnumb.txt" FOR INPUT AS #1
DO
INPUT #1, n1: PRINT n1;
INPUT #1, n2: PRINT n2;
INPUT #1, n3: PRINT n3;
INPUT #1, n4: PRINT n4;
INPUT #1, n5: PRINT n5;
INPUT #1, n6: PRINT n6;
INPUT #1, n7: PRINT n7
IF n7 <> pn7 THEN subs = 1: s1 = s1 + 1
excl(s1) = n7
pn7 = n7
avail(s1, subs, 1) = n1
avail(s1, subs, 2) = n2
avail(s1, subs, 3) = n3
avail(s1, subs, 4) = n4
avail(s1, subs, 5) = n5
subs = subs + 1
LOOP UNTIL EOF(1)
fillIn 1
CLOSE
SUB fillIn (intr)
SELECT CASE intr
CASE 1
rowC = 6: rowV = 49
colR = 3: colV = 24
CASE 2
rowC = 3: rowV = 17
colR = 5: colV = 43
CASE 3
rowC = 1: rowV = 24
colR = 2: colV = 17
CASE 4
rowC = 5: rowV = 7
colR = 6: colV = 10
CASE 5
rowC = 2: rowV = 43
colR = 4: colV = 7
CASE 6
rowC = 4: rowV = 10
colR = 1: colV = 49
END SELECT
FOR i = 1 TO 6
IF excl(i) = rowV THEN s1a = i: EXIT FOR
NEXT
grid(intr, rowC) = rowV
FOR s2a = 1 TO 200
IF intr = 1 THEN PRINT s2a
good = 1
upto = 0
IF avail(s1a, s2a, 1) > 0 THEN
FOR col = 1 TO 6
IF col <> rowC THEN
upto = upto + 1
IF col < intr THEN
IF grid(intr, col) <> avail(s1a, s2a, upto) THEN
good = 0: EXIT FOR
END IF
ELSE
grid(intr, col) = avail(s1a, s2a, upto)
END IF
END IF
NEXT
IF good THEN
FOR i = 1 TO 6
IF excl(i) = colV THEN s1 = i: EXIT FOR
NEXT
grid(colR, intr) = colV
FOR s2 = 1 TO 200
good = 1
upto = 0
IF avail(s1, s2, 1) > 0 THEN
FOR row = 1 TO 6
IF row <> colR THEN
upto = upto + 1
IF row <= intr THEN
IF grid(row, intr) <> avail(s1, s2, upto) THEN
good = 0: EXIT FOR
END IF
ELSE
grid(row, intr) = avail(s1, s2, upto)
END IF
END IF
NEXT
IF good THEN
IF intr = 6 THEN
t1 = 0: t2 = 0
FOR ii = 1 TO 6
t1 = t1 + grid(ii, ii): t2 = t2 + grid(ii, 7 - ii)
NEXT
IF t1 = 86 AND t2 = 86 THEN
PRINT "*****"
END IF
FOR r = 1 TO 6
FOR c = 1 TO 6
PRINT USING "###"; grid(r, c);
NEXT
PRINT
NEXT
IF t1 = 86 AND t2 = 86 THEN
PRINT "*****"
END IF
PRINT
IF t1 = 86 AND t2 = 86 THEN
PRINT #2, "*****"
END IF
FOR r = 1 TO 6
FOR c = 1 TO 6
PRINT #2, USING "###"; grid(r, c);
NEXT
PRINT #2,
NEXT
IF t1 = 86 AND t2 = 86 THEN
PRINT #2, "*****"
END IF
PRINT #2,
ELSE
fillIn intr + 1
END IF
END IF
ELSE
EXIT FOR
END IF
NEXT
END IF
ELSE
EXIT FOR
END IF
IF intr = 1 THEN
REM
END IF
NEXT
END SUB
|
Posted by Charlie
on 2007-03-16 09:47:29 |