Saturday, March 31, 2012

magic square

You have a 3x3 square, fill with integers such that the sum for each row, for each column and in diagonal is 15. All the numbers must be different.

Hint: brute force is difficult (how many?), what would be number you put in the middle?

1 comment:

  1. I'm afraid you're wrong. Brute force solution runs within 0.78 sec, and it takes about 10 minutes to write it from scratch.

    The idea is that you don't need 0, and need 1-9, so that sum matches 45. Than you over-force problem for solution. As an easy corollary you understand that in center must be five, and other 4 pairs will than sum to 10 each.

    ReplyDelete