Maths square puzzle

Ok, I’m going to admit this one had me working for a few minutes with a pencil. RMB’s young son had gone to his dad for help with some maths homework, and they’d blasted through it with ease except for one question, which they eventually came to me with before calling shenanigans on the whole thing and proclaiming it broken:

O   O

In the circles above, take the numbers one through eight and arrange them so that each side of the square adds up to fifteen.

(It’s a 3×3 grid with the middle one missing if it doesn’t look right)

My first assumption was to try to put a 7 in the bottom right, 8 in the top left and try to figure it from there. I had a few goes and then threw out a brute-force table of all the options I could find.

1 6 8
2 5 8
2 6 7
3 4 8
3 5 7
4 5 6

Throwing this onto the paper I tried a few variations starting with an 8 in one spot, then mixing it around. Remembering that each of the 3-number sets above could be in any order, I eventually lucked my way onto the right one.

I really should have stuck with the original idea, because it was the best, but it was easy to think I was going the wrong way when I couldn’t get it within a few tries 🙂

As a quick example and another test for myself I wrote a quick python program to create the above set, even though it’s not the way I did it originally - was trying to test the non-programmning part of my brain for once!

items = []
nums = range( 1, 9 )

for a in nums:
    for b in nums:
        for c in nums:
            if a != b and b != c and a != c and ( a + b + c ) == 15:
                item = sorted( [ a, b, c ] )
                if item not in items:
                    items.append( item )
                    print item

If you’re looking for the answer, I really shouldn’t just give it to you - but I will 🙂

3 4 8
5   1
7 2 6

As you can see, the original assumption was correct - put the two biggest numbers into the spots where they’ll do the most good, then work it out from there.

#fun #logic puzzle #math #python