Jump to content
BrainDen.com - Brain Teasers
  • 0


bushindo
 Share

Question

Here's a challenge. We all know that a magic square is an arrangement of integers from 1 to n2 such that the sum on each row, column, and diagonal adds to the same sum. Extend that to three dimension. Using integers 1 to 27, construct a 3x3x3 arrangement so that the sum on each row, column, pillar, and the four main diagonal adds up to the same sum.

1) What is this common sum for the 3x3x3 arrangement?

2) What is this arrangement?

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Here's two solutions - I think the magic number will always be 42 and I think they are 162 solutions.

Top Layer:

1 15 26

17 19 6

24 8 10

Middle Layer:

23 7 12

3 14 25

16 21 5

Bottom Layer:

18 20 4

22 9 11

2 13 27

Top Layer:

3 17 22

23 1 18

16 24 2

Middle Layer:

13 21 8

9 14 19

20 7 15

Bottom Layer:

26 4 12

10 27 5

6 11 25

Link to comment
Share on other sites

  • 0

Here's two solutions - I think the magic number will always be 42 and I think they are 162 solutions.

Top Layer:

1 15 26

17 19 6

24 8 10

Middle Layer:

23 7 12

3 14 25

16 21 5

Bottom Layer:

18 20 4

22 9 11

2 13 27

Top Layer:

3 17 22

23 1 18

16 24 2

Middle Layer:

13 21 8

9 14 19

20 7 15

Bottom Layer:

26 4 12

10 27 5

6 11 25

Nicely done. If you're not too busy, I'd like to know how you approached this problem.

Link to comment
Share on other sites

  • 0

I actually wrote a brute force program with some optimizations.

This presented an interesting problem because of the size of the state space. I used a recursive backtracking function with two arrays (an array representing unused digits initially containing 1 through 27 in order and an array representing the permutation with index 0 being the top layer top right square, 1 being the top layer top middle square, etc) that generated permutations of size x. At x=3 you calculate the magic number of your current permutation. Then at certain values of x you have enough information to check if the magic cube is valid. For example, when x=6 you can check if middle row of the first layer equals the magic number and at x=18 you can check the top left pillar. If your check succeeds, you just pass the current permutation; the list of unused numbers; and x+1 back into the function. When x=27 you print out the solution. I think the first solution was obtained in 30 minutes. I had about 24 solutions when I killed the program a day later. There were about 6 solutions for permutations starting with 1, 6 for those starting with 2, etc. So I just estimated 6x27=162 but I think that may be off.

I would love to here a way to solve this without using an exhaustive search.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...