Constructing Magic Squares: an integer constraint satisfaction problem and a fast approach
Abstract
Magic squares are a fascinating mathematical challenge that has intrigued mathematicians for centuries. Given a positive (and possibly large) integer \( n \), one of the main challenges that still remains is to find, within a computational time, a magic square of order \( n \), that is, a square matrix of order \( n \) with unique integers from \( a \) to \( a \), such that the sum of each row, column, and diagonal equals a constant \( C(A) \). In this work, we first present an integer constraint satisfaction problem for constructing a magic square of order \( n \). Nonetheless, the solution time of this problem grows exponentially as the order increases. To overcome this limitation, we also propose a that constructs magic squares depending on whether \( n \) is odd, singly even, or doubly even. Moreover, we provide a proof of the correctness of this novel approach. Our numerical results show that our method can construct magic squares of order up to 70000 in less than 140 seconds, demonstrating its efficiency and scalability.
Turn this paper into a full lesson
ArcXiv compiles a staged curriculum from this paper: 8-12 lessons across beginner → advanced, synthesised section guides, visuals, flashcards, a quiz, exercises, and on-demand deep dives per section. Grounded in the abstract, never invented.