All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Just Math
Counting magic squares (Posted on 2018-06-30) Difficulty: 2 of 5
How many magic squares are there using each the numbers 1 to 9 exactly once?

Show all of them and explain why your set is final.

See The Solution Submitted by Ady TZIDON    
Rating: 2.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Comment 2 of 2 |
There are 8 solutions, and seven are rotations and/or reflections of a single unique solution.

Reasoning (a way clumsy proof, but it works): 

Since there are 9 elements, it is a 3x3. 

The central square must be occupied by 1, 5 or 9. Why? 

Since there are the 4 cuts passing through the center that must add to the same sum, then these 8 boarder squares (since they contribute pairwise to only one center-cut sum) must add to a number divisible by 4. The sum 1:9 is 45. (45 - center) is divisible by 4. So the boarder must add to 44, 40 or 36. So center is 1, 5, or 9. Thus, the only possibilities for the center cuts and remaining boarder squares are:

912 813 714 615  leaving Boarder ring (23456789) (cut sum=12)

951 852 753 654  leaving Boarder ring (12346789) (cut sum=15)

891 792 693 594  leaving Boarder ring (12345678) (cut sum=18)

Now the boarder ring must yield 4 ways to add three elements 
to make "sum", i.e., the two sides and the top and bottom cuts. The first Boarder ring is hopeless since 9 looks for 2 elements to add to 12. Likewise the third boarder ring is hopeless: what will add to 1 to make 18? The sum=5 boarder ring satisfies: 
 834, 492, 276, 618 all add to 15. Putting the ring as 27618349 or its reflection 29438167, gives the sequence of the 4 listed sums to 15, and each ring has four rotations allowed which leave 2648 in the corners where they belong.

Solutions:


--- 1 ---

2 7 6

9 5 1

4 3 8

 

--- 2 ---

2 9 4

7 5 3

6 1 8


--- 3 ---

4 3 8

9 5 1

2 7 6


--- 4 --- 

4 9 2

3 5 7

8 1 6


--- 5 ---

6 1 8

7 5 3

2 9 4

    

--- 6 ---

6 7 2

1 5 9

8 3 4

    

--- 7 ---

8 1 6

3 5 7

4 9 2

 

--- 8 ---

8 3 4

1 5 9

6 7 2

Program (I was finished learning Fortran before "WHILE" was invented)


        program sq3

        implicit none

        integer sq(9),i1,i2,i3,i4,i5,i6,i7,i8,i9,cnt,

        1 sum1,sum2,sum3,sum4,sum5,sum6,sum7,sum8

        cnt=0

         do 1 i1=1,9

                  do 2 i2=1,9

        if(i2.eq.i1)go to 2

           do 3 i3=1,9

        if(i3.eq.i1.or.i3.eq.i2)go to 3

            do 4 i4=1,9

        if(i4.eq.i1.or.i4.eq.i2.or.i4.eq.i3)go to 4

             do 5 i5=1,9

        if(i5.eq.i1.or.i5.eq.i2.or.i5.eq.i3.or.

        1  i5.eq.i4)go to 5

              do 6 i6=1,9

        if(i6.eq.i1.or.i6.eq.i2.or.i6.eq.i3.or.

        1  i6.eq.i4.or.i6.eq.i5)go to 6

               do 7 i7=1,9

        if(i7.eq.i1.or.i7.eq.i2.or.i7.eq.i3.or.

        1  i7.eq.i4.or.i7.eq.i5.or.i7.eq.i6)go to 7

                do 8 i8=1,9

        if(i8.eq.i1.or.i8.eq.i2.or.i8.eq.i3.or.

        1  i8.eq.i4.or.i8.eq.i5.or.i8.eq.i6.or.

        2  i8.eq.i7)go to 8

                 do 9 i9=1,9

        if(i9.eq.i1.or.i9.eq.i2.or.i9.eq.i3.or.

        1  i9.eq.i4.or.i9.eq.i5.or.i9.eq.i6.or.

        2  i9.eq.i7.or.i9.eq.i8)go to 9



        sum1=i1+i4+i7

        sum2=i2+i5+i8

        sum3=i3+i6+i9

        sum4=i1+i2+i3

        sum5=i4+i5+i6

        sum6=i7+i8+i9

        sum7=i1+i5+i9

        sum8=i3+i5+i7

        if(sum1.eq.sum2.and.sum1.eq.sum3.and.

        1  sum1.eq.sum4.and.sum1.eq.sum5.and.

        2  sum1.eq.sum6.and.sum1.eq.sum7.and.

        3  sum1.eq.sum8)then

        cnt=cnt+1

        print 10,cnt,i1,i2,i3,i4,i5,i6,i7,i8,i9

10      format(i5,/,20('-'),/,3(i1,1x),/)

        endif

9                enddo

8               enddo

7              enddo

6             enddo

5            enddo

4           enddo

3          enddo

2         enddo

1        enddo

        end


Edited on July 12, 2018, 8:09 pm
  Posted by Steven Lord on 2018-07-12 04:48:37

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (5)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information