Magic Squares of Odd Order

The Mamzeris Method: Algorithmic construction and universal closed-form formula for associative magic squares of any odd order

Smaragdos (Marios) Mamzeris

Magic Squares of odd order

3x3 magic square example demonstrating the Mamzeris Method for odd-order construction

Magic Squares of odd order by Marios Mamzeris


This page presents the Mamzeris Method: a systematic approach to constructing associative magic squares of any odd order using simple two-pass transformations or direct mathematical formulas.

The Origin Story

I developed this method in 1988 while studying computer science. When my university's mathematics faculty presented what they called an 'unsolved problem' in magic square construction, they challenged me to apply my programming background to find a systematic solution. What emerged was a universal algorithmic method that works for any odd-order magic square. I used this method personally for over three decades before publishing it in 2020, along with a new universal closed-form formula that enables direct calculation of any cell position.

A Magic Square is an n × n square grid (where n is the number of cells on each side) filled with distinct positive integers in the range 1,2,...,n2 such that each cell contains a different integer and the sum of integers in each row, column, and diagonal is equal.

An associative magic square has an elegant property: pairs of numbers positioned symmetrically opposite the centre always sum to n2 + 1. For example, in a 7×7 square (n²=49), opposite pairs sum to 50. These are also called symmetric magic squares, and all associative magic squares are self-complementary. (Wikipedia)


The Mamzeris Method offers two complementary approaches:

1. Algorithmic Construction (detailed below): A two-pass table transformation using row and column shifts. Best for learning, teaching, or manual construction.

2. Universal Closed-Form Formula: A direct mathematical formula that computes the value of any cell position (x, y) for any odd order N. This formula was first published in 2025 and enables instant calculation without iterative steps. Best for programming, large squares, or individual cell calculations. View the complete mathematical formula

Algorithmic Construction Method:

To create any odd-order associative magic square quickly and efficiently using the algorithmic approach, we need to perform only two simple passes, which I call table transformations (shifts). The three tables below demonstrate the construction of a 31×31 magic square.

Pass 1: Begin with a table filled sequentially with all numbers from 1 to n2 (1st table below, with cells shifting shown in green). Perform a left shift of all rows, skipping the middle one: shift the first row by one cell, the second row by two cells, and so on, until the last (nth) row is shifted by n−1 cells.

Pass 2: Apply a similar transformation to columns instead of rows. Shift cells upward, starting with one cell in the leftmost column, two cells in the next column, and so on, until the last (nth) column is shifted by n−1 cells, skipping the middle column. This is shown in the 2nd table below with cells shifting in blue.

That's it. A magic square is ready. The completed square is shown in the 3rd table below, with alternating grey cells and highlighted yellow diagonals.



1. Initial Table: Begin with numbers from 1 to n2 arranged sequentially
The green arrow indicates the direction of the upcoming cell shift. Green-highlighted cells show which cells will move.

Left green arrow

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
   
1   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
2   32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
3   63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
4   94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
5   125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
6   156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
7   187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
8   218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
9   249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
10   280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
11   311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
12   342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
13   373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
14   404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
15   435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
16   466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
17   497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
18   528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
19   559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
20   590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
21   621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
22   652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
23   683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
24   714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
25   745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
26   776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
27   807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
28   838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
29   869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
30   900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
31   931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961

 


2. After First Pass: Rows shifted, columns ready for transformation
The blue arrow indicates the direction of the second shift. Blue-highlighted cells show which cells will move.

Up blue arrow

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
   
1   2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1
2   34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 32 33
3   66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 63 64 65
4   98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 94 95 96 97
5   130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 125 126 127 128 129
6   162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 156 157 158 159 160 161
7   194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 187 188 189 190 191 192 193
8   226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 218 219 220 221 222 223 224 225
9   258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 249 250 251 252 253 254 255 256 257
10   290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 280 281 282 283 284 285 286 287 288 289
11   322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 311 312 313 314 315 316 317 318 319 320 321
12   354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 342 343 344 345 346 347 348 349 350 351 352 353
13   386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 373 374 375 376 377 378 379 380 381 382 383 384 385
14   418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 404 405 406 407 408 409 410 411 412 413 414 415 416 417
15   450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
16   466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
17   513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
18   545 546 547 548 549 550 551 552 553 554 555 556 557 558 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
19   577 578 579 580 581 582 583 584 585 586 587 588 589 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
20   609 610 611 612 613 614 615 616 617 618 619 620 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
21   641 642 643 644 645 646 647 648 649 650 651 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
22   673 674 675 676 677 678 679 680 681 682 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
23   705 706 707 708 709 710 711 712 713 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
24   737 738 739 740 741 742 743 744 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
25   769 770 771 772 773 774 775 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
26   801 802 803 804 805 806 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
27   833 834 835 836 837 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
28   865 866 867 868 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
29   897 898 899 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896
30   929 930 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928
31   961 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960

 


3. Completed Magic Square: Final result after both transformations
All rows, columns, and diagonals now sum to the magic constant. Grey cells alternate for visibility, and yellow highlights show the main diagonals.

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
   
1   34 67 100 133 166 199 232 265 298 331 364 397 430 463 480 17 498 531 564 597 630 663 696 729 762 795 828 861 894 927 960
2   66 99 132 165 198 231 264 297 330 363 396 429 462 479 527 49 530 563 596 629 662 695 728 761 794 827 860 893 926 959 1
3   98 131 164 197 230 263 296 329 362 395 428 461 478 526 528 81 562 595 628 661 694 727 760 793 826 859 892 925 958 31 33
4   130 163 196 229 262 295 328 361 394 427 460 477 525 558 560 113 594 627 660 693 726 759 792 825 858 891 924 957 30 32 65
5   162 195 228 261 294 327 360 393 426 459 476 524 557 559 592 145 626 659 692 725 758 791 824 857 890 923 956 29 62 64 97
6   194 227 260 293 326 359 392 425 458 475 523 556 589 591 624 177 658 691 724 757 790 823 856 889 922 955 28 61 63 96 129
7   226 259 292 325 358 391 424 457 474 522 555 588 590 623 656 209 690 723 756 789 822 855 888 921 954 27 60 93 95 128 161
8   258 291 324 357 390 423 456 473 521 554 587 620 622 655 688 241 722 755 788 821 854 887 920 953 26 59 92 94 127 160 193
9   290 323 356 389 422 455 472 520 553 586 619 621 654 687 720 273 754 787 820 853 886 919 952 25 58 91 124 126 159 192 225
10   322 355 388 421 454 471 519 552 585 618 651 653 686 719 752 305 786 819 852 885 918 951 24 57 90 123 125 158 191 224 257
11   354 387 420 453 470 518 551 584 617 650 652 685 718 751 784 337 818 851 884 917 950 23 56 89 122 155 157 190 223 256 289
12   386 419 452 469 517 550 583 616 649 682 684 717 750 783 816 369 850 883 916 949 22 55 88 121 154 156 189 222 255 288 321
13   418 451 468 516 549 582 615 648 681 683 716 749 782 815 848 401 882 915 948 21 54 87 120 153 186 188 221 254 287 320 353
14   450 467 515 548 581 614 647 680 713 715 748 781 814 847 880 433 914 947 20 53 86 119 152 185 187 220 253 286 319 352 385
15   466 514 547 580 613 646 679 712 714 747 780 813 846 879 912 465 946 19 52 85 118 151 184 217 219 252 285 318 351 384 417
16   513 546 579 612 645 678 711 744 746 779 812 845 878 911 944 481 18 51 84 117 150 183 216 218 251 284 317 350 383 416 449
17   545 578 611 644 677 710 743 745 778 811 844 877 910 943 16 497 50 83 116 149 182 215 248 250 283 316 349 382 415 448 496
18   577 610 643 676 709 742 775 777 810 843 876 909 942 15 48 529 82 115 148 181 214 247 249 282 315 348 381 414 447 495 512
19   609 642 675 708 741 774 776 809 842 875 908 941 14 47 80 561 114 147 180 213 246 279 281 314 347 380 413 446 494 511 544
20   641 674 707 740 773 806 808 841 874 907 940 13 46 79 112 593 146 179 212 245 278 280 313 346 379 412 445 493 510 543 576
21   673 706 739 772 805 807 840 873 906 939 12 45 78 111 144 625 178 211 244 277 310 312 345 378 411 444 492 509 542 575 608
22   705 738 771 804 837 839 872 905 938 11 44 77 110 143 176 657 210 243 276 309 311 344 377 410 443 491 508 541 574 607 640
23   737 770 803 836 838 871 904 937 10 43 76 109 142 175 208 689 242 275 308 341 343 376 409 442 490 507 540 573 606 639 672
24   769 802 835 868 870 903 936 9 42 75 108 141 174 207 240 721 274 307 340 342 375 408 441 489 506 539 572 605 638 671 704
25   801 834 867 869 902 935 8 41 74 107 140 173 206 239 272 753 306 339 372 374 407 440 488 505 538 571 604 637 670 703 736
26   833 866 899 901 934 7 40 73 106 139 172 205 238 271 304 785 338 371 373 406 439 487 504 537 570 603 636 669 702 735 768
27   865 898 900 933 6 39 72 105 138 171 204 237 270 303 336 817 370 403 405 438 486 503 536 569 602 635 668 701 734 767 800
28   897 930 932 5 38 71 104 137 170 203 236 269 302 335 368 849 402 404 437 485 502 535 568 601 634 667 700 733 766 799 832
29   929 931 4 37 70 103 136 169 202 235 268 301 334 367 400 881 434 436 484 501 534 567 600 633 666 699 732 765 798 831 864
30   961 3 36 69 102 135 168 201 234 267 300 333 366 399 432 913 435 483 500 533 566 599 632 665 698 731 764 797 830 863 896
31   2 35 68 101 134 167 200 233 266 299 332 365 398 431 464 945 482 499 532 565 598 631 664 697 730 763 796 829 862 895 928

 



Alternative Approach: Bidirectional Shifting

Instead of shifting all rows in one direction and all columns in another, you can shift each half of the table in opposite directions (always skipping the middle row or column). This produces the same result using a mirror-symmetry pattern.


Initial square with numbers 1 - n2 in sequence

Blue arrow left
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35
36 37 38 39 40 41 42
43 44 45 46 47 48 49
                                   blue arrow right 


After the first pass: Notice how each column is equal to Σ

    Green arrow up
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2 3 4 5 6 7 1   















 
 
 



 Green arrow down
10 11 12 13 14 8 9
18 19 20 21 15 16 17
22 23 24 25 26 27 28
33 34 35 29 30 31 32
41 42 36 37 38 39 40
49 43 44 45 46 47 48

 

Second pass completed: Now each row is also equal to Σ. The Magic Square is ready!

 10  19  24  5  30  39  48
 18  23  35  13  38  47  1
 22  34  36  21  46  7  9
 33  42  44  25  6  8  17
 41  43  4  29  14  16  28
 49  3  12  37  15  27  32
 2  11  20  45  26  31  40



Universal Closed-Form Formula

In addition to the algorithmic construction method described above, the Mamzeris Method includes a universal closed-form formula that directly computes the value at any cell position without performing iterative shifts. This formula is set out in my paper, Universal Closed-Form Construction for Odd-Order Magic Squares (The Mamzeris Method).

Key advantages of the closed-form formula:

  • Direct computation: Calculate any individual cell value without constructing the entire square
  • Computational efficiency: Ideal for programming, large squares, or sparse calculations
  • Mathematical completeness: Provides explicit mathematical expression for the entire construction
  • Validation tool: Verify algorithmic constructions or explore specific patterns

The formula

Given an odd order N ≥ 3 and a position (x, y) with 1 ≤ x, yN, where x is the column and y is the row, both counted from one:

M = ( N + 1 ) / 2
s(i) = 0if i = M iif i < M i − 1if i > M
Y = ( ( y − 1 + s(x) ) mod N ) + 1
X = ( ( x − 1 + s(Y) ) mod N ) + 1
V(x, y; N) = N ( Y − 1 ) + X

Note the order. The column shift is undone first, which produces Y, and the row shift is then undone using s(Y), not s(y). The construction shifts the rows first and the columns second, so to find what ends up at a given position the two operations must be undone in the reverse order. This is the single point at which readers most often go wrong.

A full derivation, eight worked examples covering every branch of the shift function, the completed 5 × 5, 7 × 7 and 11 × 11 squares, and the zero-based form of the same result are given in the published paper.

Worked example. The value at column 3, row 4 of a 5 × 5 square:

N = 5,   M = ( 5 + 1 ) / 2 = 3,   x = 3,   y = 4
s(3) = 0   because 3 = M, the central column
Y = ( ( 4 − 1 + 0 ) mod 5 ) + 1 = ( 3 mod 5 ) + 1 = 4
s(4) = 3   because 4 > M
X = ( ( 3 − 1 + 3 ) mod 5 ) + 1 = ( 5 mod 5 ) + 1 = 1
V(3, 4; 5) = 5 × ( 4 − 1 ) + 1 = 16

Reading row 4, column 3 of the completed 5 × 5 square shown further down this page confirms the value 16. Remember that x is the column and y is the row; reading the pair the other way round will give the wrong cell.

The formula has been checked cell by cell against the algorithmic construction for every odd order from 3 to 121 inclusive. Every entry agrees, and every resulting square is a genuine associative magic square. The two approaches are therefore complementary rather than alternative: the algorithm is the better way to understand the construction, and the formula is the better way to compute with it.



Understanding How the Method Works

This section explains the mathematical insight behind why the two-pass transformation creates a magic square of odd order. Understanding the balance of row and column sums reveals the elegance of the method.

Key Variables:

n = the square's dimension (for a 7×7 square, n = 7)
M = (n2 + 1)/2 = the middle number (located at the center)
Σ = M×n = the magic constant (target sum for each row, column, and diagonal)
r = distance from the middle row or column

The Balancing Principle:

When we fill the initial square (1) with numbers 1 to
n2 in sequence, each row and column has a different sum based on its distance from the center. This creates predictable "weight" imbalances:

For columns:
• Moving left from center: each column's sum =
Σ - r×n
• Moving right from center: each column's sum =
Σ + r×n

For rows:
• Moving up from center: each row's sum =
Σ - (r×n2)
• Moving down from center: each row's sum =
Σ + (r×n2)

Pass 1 - Balancing the Rows:

The first pass shifts cells left by increasing amounts (row 1 shifts by 1, row 2 by 2, etc.), skipping the middle row. This creates square (2) where all row sums equal
Σ.

The key insight: cells shifted off the left edge wrap to the right, adding exactly the right amount to compensate for each row's initial imbalance. The top row gains +1, the next gains +2, and so on, perfectly counterbalancing the initial deficits.

Pass 2 - Balancing the Columns:

The second pass applies the same logic to columns, shifting cells upward by increasing amounts. This transforms square (2) into square (3), where all column sums also equal
Σ, creating a perfect magic square.

Visual Guide to the Tables Below:

Left tables: Show each cell's value relative to
n (the algebraic view)
Right tables: Show actual numeric values as the square transforms
Green cells: Display row and column sums (diagonals always equal
Σ)
Blue cells: Track the middle row and column positions through both passes
Square (3): The completed magic square with all properties satisfied


                  1st stage of magic square                      
                Σ                   175   Σ
n-6 n-5 n-4 n-3 n-2 n-1 n Σ -(3n2) 1 2 3 4 5 6 7 28 Σ -(3n2)
n+1 n+2 n+3 n+4 n+5 n+6 n+7 Σ -(2n2) 8 9 10 11 12 13 14 77 Σ -(2n2)
n+8 n+9 n+10 n+11 n+12 n+13 n+14 Σ -(1n2) 15 16 17 18 19 20 21 126 Σ -(1n2)
n+15 n+16 n+17 n+18 n+19 n+20 n+21 Σ 22 23 24 25 26 27 28 175 Σ
n+22 n+23 n+24 n+25 n+26 n+27 n+28 Σ +(1n2) 29 30 31 32 33 34 35 224 Σ +(1n2)
n+29 n+30 n+31 n+32 n+33 n+34 n+35 Σ +(2n2) 36 37 38 39 40 41 42 273 Σ +(2n2)
n+36 n+37 n+38 n+39 n+40 n+41 n+42 Σ +(3n2) 43 44 45 46 47 48 49 322 Σ +(3n2)
Σ 175 Σ
                154 161 168 175 182 189 196  
Σ -(3n) Σ -(2n) Σ -(1n) Σ Σ +(1n) Σ +(2n) Σ +(3n) Σ -(3n) Σ -(2n) Σ -(1n) Σ Σ +(1n) Σ +(2n) Σ +(3n)
                  2nd stage of magic square                      
Σ   175 Σ
n-5 n-4 n-3 n-2 n-1 n n-6 Σ -(3n2) 2 3 4 5 6 7 1 28 Σ -(3n2)
n+3 n+4 n+5 n+6 n+7 n+1 n+2 Σ -(2n2) 10 11 12 13 14 8 9 77 Σ -(2n2)
n+11 n+12 n+13 n+14 n+8 n+9 n+10 Σ -(1n2) 18 19 20 21 15 16 17 126 Σ -(1n2)
n+15 n+16 n+17 n+18 n+19 n+20 n+21 Σ 22 23 24 25 26 27 28 175 Σ
n+26 n+27 n+28 n+22 n+23 n+24 n+25 Σ +(1n2) 33 34 35 29 30 31 32 224 Σ +(1n2)
n+34 n+35 n+29 n+30 n+31 n+32 n+33 Σ +(2n2) 41 42 36 37 38 39 40 273 Σ +(2n2)
n+42 n+36 n+37 n+38 n+39 n+40 n+41 Σ +(3n2) 49 43 44 45 46 47 48 322 Σ +(3n2)
Σ 175 Σ
                175 175 175 175 175 175 175
Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ
                  3rd stage of magic square                      
Σ   175 Σ
n+3 n+12 n+17 n-2 n+23 n+32 n+41 Σ 10 19 24 5 30 39 48 175 Σ
n+11 n+16 n+28 n+6 n+31 n+40 n-6 Σ 18 23 35 13 38 47 1 175 Σ
n+15 n+27 n+29 n+14 n+39 n n+2 Σ 22 34 36 21 46 7 9 175 Σ
n+26 n+35 n+37 n+18 n-1 n+1 n+10 Σ 33 42 44 25 6 8 17 175 Σ
n+34 n+36 n-3 n+22 n+7 n+9 n+21 Σ 41 43 4 29 14 16 28 175 Σ
n+42 n-4 n+5 n+30 n+8 n+20 n+25 Σ 49 3 12 37 15 27 32 175 Σ
n-5 n+4 n+13 n+38 n+19 n+24 n+33 Σ 2 11 20 45 26 31 40 175 Σ
Σ 175 Σ
                175 175 175 175 175 175 175  
Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ Σ



 

Magic Square Alternatives

Variations

The Mamzeris Method is remarkably flexible. From the same starting table it produces four different magic squares of the same order. Two things may be varied, and each has two settings:

The shift directions: rows left with columns up, or rows right with columns down
The order of the two passes: rows shifted first, or columns shifted first

Two direction settings multiplied by two pass orders give four distinct squares. All four are shown below, first for order 5 and then for order 19.

A warning about the shift directions. Only two of the four possible direction pairs give a magic square: rows left with columns up, and rows right with columns down. The mixed pairs, rows left with columns down and rows right with columns up, do not. They give correct column sums and correct diagonal sums, and the result is still associative, so a partial check appears to pass. The row sums are wrong. Anyone verifying the method must check the rows as well as the columns.

The order of the two passes. Shifting the rows first and then the columns gives one square. Shifting the columns first and then the rows gives a genuinely different square. This is the second source of variation, and combined with the two working direction pairs it accounts for all four squares.

The two pass orders are not related to one another by any rotation or reflection. Verified by enumeration at orders 5, 7 and 9, the square obtained by shifting the columns first never appears among the eight rotations and reflections of the square obtained by shifting the rows first.

The four squares, shown in full for order 5

Every one of the four starts from the same table, the numbers 1 to 25 written in reading order. The colours mark which row of that starting table each number came from, so the movement can be followed by eye. The central row is grey because it never moves.

The starting table
12345
678910
1112131415
1617181920
2122232425
Variation 1
81241724
112010231
19211357
25316615
29221418
Rows shifted first, then columns. Rows move left, columns move up.
Variation 2
22192148
52361615
91132517
111020321
18122474
Rows shifted first, then columns. Rows move right, columns move down.
Variation 3
12319256
82451117
162213410
91521218
20172314
Columns shifted first, then rows. Rows move left, columns move up.
Variation 4
102117314
19151228
62132420
18425117
12239516
Columns shifted first, then rows. Rows move right, columns move down.

In all four squares every row, every column and both diagonals total 65, and every pair of cells placed symmetrically about the centre totals 26. The four are genuinely different: none is a rotation, a reflection or a transpose of any other.

The same four variations at order 19, with every number shown. Each cell is shaded on a single scale running from red at the lowest values through white at the middle to blue at the highest, so the pattern each variation creates can be seen at a glance. Every row, column and main diagonal in all four squares totals 3,439, and every pair of cells placed symmetrically about the centre totals 362.

Variation 1
2243648510612714816918011192213234255276297318339360
426384105126147168179209312122332542752963173383591
6283104125146167178208210512322532742953163373581921
8210312414516617720722823071252273294315336357182041
1021231441651762062272292509127229331433535617384061
1221431641752052262472492701112923133343551637396081
1421631742042252462482692901313123333541536575980101
1621732032242452662682893101513323531435565879100121
172202223244265267288309330171352133455767899120141
201222243264285287308329350181123354757798119140161
221242263284286307328349101913253749597118139160190
24126228330430632734893021152739496117138159189200
261282303305326347829502317293114116137158188199220
281302323325346728497025192113115136157187198219240
301322324345627486990271112133135156186197218239260
321342344526476889110291132134155185196217238259280
341343425466788109130311152154184195216237258279300
361324456687108129150331153183194215236257278299320
223446586107128149170351182193214235256277298319340
Rows shifted first, then columns. Rows move left, columns move up.
Variation 2
344327310293276259242225208918215513812110487705336
1934532831129427726024322627191183156139122105887154
371346329312295278261244452281921841571401231068972
553823473303132962792626324621019318515814112410790
735620334833131429728081264247211194186159142125108
91745721434933231529899282265229212195187160143126
109927539225350333316117300283266230213196188161144
127110937640236351334135318301284248231214197189162
145128111945841247352153336319302285249232215198190
163146129112955942258181354337320303267250233216199
1721641471301137760432620910355338321304268251234217
2001731651481311147861442272811356339322286269252235
218201174166149132967962245462912357340323287270253
236219202175167150133978026364473013358341305288271
254237220203176168151115982818265483114359342306289
2722552382212041771691521162991008366493215360324307
2902732562392222051781701343171181018467503316361325
3082912742572402232061791713351361191028568513417343
3263092922752582412242071803531541371201038669523518
Rows shifted first, then columns. Rows move right, columns move down.
Variation 3
4060801001201401601801020122124126128130132134136120
799911913915917919929220240260280300320340360193959
118138158178198218482392592792993193393591838587898
157177197217237672582782983183383581737577797117137
196216236256862772973173373571636567696116136156176
2352552751052963163363561535557595115135155175195215
2742941243153353551434547494114134154174194214234254
3131433343541333537393113133153173193213233253273293
1623531232527292112132152172192212232252272292312332
1912112312512712913113313511811131517191111131151171
305070901101301501701902102302502702903103303509200
698910912914916918920922924926928930932934982821949
108128148168188208228248268288308328348727472386888
147167187207227247267287307327347626466625787107127
186206226246266286306326346525456585276106126146166
225245265285305325345424446484104295125145165185205
264284304324344323436383103123314144164184204224244
303323343222426282102122142333163183203223243263283
342121416181101121141161352182202222242262282302322
Columns shifted first, then rows. Rows move left, columns move up.
Variation 4
3834332530728927125323521719910182164146128110927456
755713443263082902722542362182920118316514712911193
112947620234532730929127325523748220202184166148130
149131113953921334632831029227425667239221203185167
186168150132114584022434732931129327586258240222204
223205187169151133775941235348330312294105277259241
26024222420618817015296786042246349331313124296278
29727926124322520718917111597796143257350332143315
33431629828026224422620819013411698806244268351162
15313511799816345279181353335317299281263245227209
2001135433631830028226424622817215413611810082644628
4721930123553373193012832652471911731551371191018365
8466238493113356338320302284266210192174156138120102
1211038525768503214357339321303285229211193175157139
1581401221042768769513315358340322304248230212194176
1951771591411232951068870523416359341323267249231213
2322141961781601423141251078971533517360342286268250
2692512332151971791613331441261089072543618361305287
3062882702522342161981803521631451271099173553719324
Columns shifted first, then rows. Rows move right, columns move down.




Permutations of Magic Squares

Permutations

Beyond the four variations, the method produces many more distinct squares, because the initial table itself may be rearranged before the two shifts are applied. Its rows may be permuted, and so may its columns.

Not every rearrangement is allowed. The finished square must be associative, which means that any two cells placed symmetrically about the centre must add up to n² + 1. That holds only if the permutation preserves the central pairing, so that row i and row n + 1 − i stay together as a pair and the middle row stays in the middle. The same condition applies to the columns. A permutation that meets it is called admissible. Every admissible pair of permutations, one for the rows and one for the columns, yields a valid associative magic square, and no two pairs yield the same square.

How many admissible permutations are there

Write m = (n − 1) / 2 for the number of pairs on either side of the centre. Each pair may be placed in any of m positions and either way round, which gives 2m × m! admissible permutations along a single axis. Applying this independently to the rows and to the columns squares that figure:

( 2m × m ! ) 2    where   m = n1 2

For a 7×7 square that is 48 admissible permutations of the rows and 48 of the columns, so 2,304 different initial tables, each of which produces a different magic square.

The unit P

The published papers carry a single symbol, P, so that the various totals can be written compactly. It is defined as:

P = 2 n3 × ( n1 2 ! ) 2

P is a unit of measurement rather than a count of anything on its own. Its only purpose is to keep the totals short. The quantity that genuinely counts something is the number of admissible initial tables, and that is exactly four times P, since (2m × m!)² = 4P for every odd n. At order 7, P = 576 and the 2,304 initial tables counted above are 4P.

The rising ladder

Every square in the three steps below is a different square. Nothing is merged, and nothing is treated as equivalent to anything else. If the squares were printed on paper and laid side by side, no two would look the same.

4P  —  one setting. Fix the pass order, say the rows are shifted first, and fix the direction, say rows to the left and columns upwards. Running every admissible initial table through that one setting gives 4P squares. At order 7 that is 2,304.

8P  —  both working directions. Keep the same pass order but allow both of the direction pairs that work, rows left with columns up, and rows right with columns down. The two sets have no square in common, so the count doubles. At order 7 that is 4,608.

16P  —  both pass orders as well. Now allow the columns to be shifted before the rows as well as after. Again the new set shares no square with the old one, so the count doubles a second time. At order 7 that is 9,216.

In one line, the factor of sixteen is:

4P admissible initial tables  ×  2 working shift directions  ×  2 pass orders  =  16P

So 16P is the complete number of distinct magic squares the Mamzeris Method can construct at any odd order from 5 upwards. The four families are entirely separate: none of the six possible overlaps between them contains a single square. Every figure in the table below has been confirmed by exhaustive enumeration at orders 5, 7 and 9.

A note on reading the paper alongside this page. Earlier releases of the closed-form paper give these counts for the rows-first pass order only, and they treat a square and its mirror image as one square. Under that convention the same results read 4P and 8P. This page counts every square that looks different on paper, and it admits both pass orders, which is why the total here is 16P. The two are not in conflict. They answer different questions, and the ladder above is the complete one.

OrderP
(the unit)
4P
one setting
8P
both directions
16P
complete total
5×51664128256
7×75762,3044,6089,216
9×936,864147,456294,912589,824
11×113,686,40014,745,60029,491,20058,982,400
13×13530,841,6002,123,366,4004,246,732,8008,493,465,600
15×15104,044,953,600416,179,814,400832,359,628,8001,664,719,257,600
17×1726,635,508,121,600106,542,032,486,400213,084,064,972,800426,168,129,945,600
19×198,629,904,631,398,40034,519,618,525,593,60069,039,237,051,187,200138,078,474,102,374,400

Order 3 is the exception. There the four families fall on top of one another instead of staying apart, and the true total is 8 rather than 16P. That figure is not a shortcoming. It is every 3×3 magic square that exists, since the 3×3 has exactly one square in eight orientations and nothing else. The method therefore produces all of them.

Two things that are deliberately not counted

Rearranging a finished square. Permuting the rows and columns of a square that has already been built is a different operation from permuting the initial table, and it is not part of the method. Almost none of the squares it produces can be built by the method at all, so they do not belong in the total. The two families are printed side by side in the published paper so the difference can be seen directly.

Filling the initial table down the columns. Writing 1 to n² down the columns instead of across the rows does produce further magic squares, but they turn out to be nothing more than the 16P squares reflected along the main diagonal. They are the same squares viewed sideways, so counting them would be counting twice.

Rearrangements that break the central pairing occasionally still give a magic square, but never an associative one, and the number of them follows no regular pattern from one order to the next. Associativity is a defining property of the method, so these are excluded.

Twelve examples at order 7 follow, each produced by permuting the rows and the columns of the initial table and then applying the two shifts. These are members of the 4P family counted above. The first is the plain case, with the initial table left in reading order. Cells are shaded by the row of the initial table each number came from, so the effect of the permutation can be followed by eye. Every square shown is a genuine associative magic square with all lines totalling 175.

Square 1
1019245303948
1823351338471
223436214679
334244256817
4143429141628
4931237152732
2112045263140
Square 2
1217263303948
1823291340457
283442154619
3136442561419
414943581622
4351037212732
2112047243338
Square 3
3833245161148
3223214110471
222083546737
1914442563631
1343415423028
493409292718
2393445261712
Square 4
4130274419113
3226213813243
221783544940
1614525453634
1014615423328
7483712292418
473931623209
Square 5
1712244737326
1123422031543
2241291444916
4035225481510
341463621928
745193082739
4418133263833
Square 6
1019245293949
1822301438476
273541164628
3337432571317
424843491523
4431236202832
1112145263140
Square 7
2037272103247
3924141934441
2212294246717
935452551541
334348213828
4961631362611
3184048231330
Square 8
3332412164641
3223156454014
282049293982
1943372513731
4842112113022
3610544352718
943438261747
Square 9
1572214473238
4264417294213
274534239919
4930402510201
3141114816523
378213362446
1218336284335
Square 10
4116272311147
1824294013447
2833141546138
308452554220
1249435361722
4363710212632
339194823349
Square 11
3402419134630
392782453321
289493632156
1243342516738
4435181414122
2917548422311
2043731261047
Square 12
1047241973929
462828383320
2714144321614
5373525151345
363418694923
3017124248224
2111433126340



Rotations and Reflections

This section answers the question every reader asks next. If the method builds 16P squares, surely turning them round and mirroring them produces still more. The answer is no, and the reason is worth seeing.

Any magic square can be turned through a quarter, a half or three quarters of a turn, and each of those can be mirrored, giving eight orientations in all. Every one of them is still a magic square, because rotating or mirroring a grid moves whole rows, columns and diagonals about without changing what is in them. The four rotations of the 3×3 square are shown below.

 

 4  3  8    8  1  6
 9  5  1    3  5  7
 2  7  6    4  9  2
      Magic Square perspectives
 6  7  2    2  9  4
 1  5  9    7  5  3
 8  3  4    6  1  8

 

What the orientations do to a Mamzeris square

Apply all eight orientations to every one of the 16P squares and a sharp division appears. Four of the eight always land back on a square the method already builds. The other four always land on a square the method cannot build at all. There are no exceptions and no borderline cases. This has been checked on every square at orders 5, 7 and 9.

OrientationResultAlready in the 16P total?
Leave as it isa Mamzeris squareYes
Turn a half turn (180°)a Mamzeris squareYes
Mirror left to righta Mamzeris squareYes
Mirror top to bottoma Mamzeris squareYes
Turn a quarter turn (90°)a magic square, but not one of oursNo
Turn three quarters (270°)a magic square, but not one of oursNo
Reflect along the main diagonala magic square, but not one of oursNo
Reflect along the other diagonala magic square, but not one of oursNo

Why the first four cannot escape. Turning an associative square through a half turn produces exactly its complement, the square in which every value v has been replaced by n² + 1 − v. That follows straight from associativity, because the value opposite any cell is already its complement, and the half turn is what brings it into place. The method always builds a square together with its complement, so the half turn has nowhere new to go. Mirroring behaves in a similar way: it carries the left-and-up family onto the right-and-down family, and both are inside the total already. The two mirrors and the half turn between them account for the whole of that group.

Why the other four fall outside. A quarter turn, or a reflection along a diagonal, interchanges the roles of the rows and the columns. The method treats the two axes differently, one shifted before the other, so the result is a magic square built by some other means, not by this construction. Not one square out of the 9,216 at order 7 survives a quarter turn and stays in the set.

The consequence for the total. Rotations and reflections add nothing. Four of them are already counted and the other four produce squares outside the method, which the method does not claim. The total stands at 16P.

Order 3 once more. At order 3 all eight orientations stay inside, because the total there is 8 and that is every 3×3 magic square in existence. The 3×3 is the only order at which the eight orientations and the method's own total are the same thing, which is why it makes a clear picture but a misleading rule.

The four variations are not orientations. This is worth stating plainly, because the two ideas are easy to confuse. The orientations above are applied to a square that is already finished, and they work on any magic square ever written down. The four variations of the Mamzeris Method come from the construction itself, from the shift directions and the order of the two passes. The four are genuinely different squares: none of them is a rotation, a reflection or a diagonal reflection of any other. That has been checked at orders 5, 7, 11, 19 and 31.



For any comments or questions, please email me at contact@oddmagicsquares.com


Smaragdos (Marios) Mamzeris - Magic Squares