Multiplication in a 3x3 grid

251 Views Asked by At

If I place all the numbers from 1 to 9 in a 3x3 grid and I add the products of each row and column, then what is the minimal sum?enter image description here For example, the sum is 450 in the picture below.

1

There are 1 best solutions below

2
On BEST ANSWER
import math
import itertools
def prod(l):
    r1 = l[0]*l[1]*l[2]
    r2 = l[3]*l[4]*l[5]
    r3 = l[6]*l[7]*l[8]
    c1 = l[0]*l[3]*l[6]
    c2 = l[1]*l[4]*l[7]
    c3 = l[2]*l[5]*l[8]
    return (r1+r2+r3+c1+c2+c3)

x = itertools.permutations([1,2,3,4,5,6,7,8,9])

minsum = math.inf

maxsum = 0

minlist = []
maxlist = []

for i in x:
    a = prod(i)
    if a < minsum:
        minlist = i
        minsum = a
    if a > maxsum:
        maxlist = i
        maxsum = a

print(minsum)
print(maxsum)
print(minlist)
print(maxlist)`

Not extremely enlightening but I ran this python code to find an answer of $436$, (and a max of $947$).