<p>Magic squares are a fascinating mathematical challenge that has intrigued mathematicians for centuries. Given a positive (and possibly large) integer <InlineEquation ID="IEq1"> <EquationSource Format="TEX">\( n \)</EquationSource> <EquationSource Format="MATHML"><math> <mi>n</mi> </math></EquationSource> </InlineEquation>, one of the main challenges that still remains is to find, within a reasonable computational time, a magic square of order <InlineEquation ID="IEq2"> <EquationSource Format="TEX">\( n \)</EquationSource> <EquationSource Format="MATHML"><math> <mi>n</mi> </math></EquationSource> </InlineEquation>, that is, a square matrix of order <InlineEquation ID="IEq3"> <EquationSource Format="TEX">\( n \)</EquationSource> <EquationSource Format="MATHML"><math> <mi>n</mi> </math></EquationSource> </InlineEquation> with unique integers from <InlineEquation ID="IEq4"> <EquationSource Format="TEX">\( a_{\min } \)</EquationSource> <EquationSource Format="MATHML"><math> <msub> <mi>a</mi> <mo movablelimits="true">min</mo> </msub> </math></EquationSource> </InlineEquation> to <InlineEquation ID="IEq5"> <EquationSource Format="TEX">\( a_{\max } \)</EquationSource> <EquationSource Format="MATHML"><math> <msub> <mi>a</mi> <mo movablelimits="true">max</mo> </msub> </math></EquationSource> </InlineEquation>, such that the sum of each row, column, and diagonal equals a constant <InlineEquation ID="IEq6"> <EquationSource Format="TEX">\( \mathcal {C}(A) \)</EquationSource> <EquationSource Format="MATHML"><math> <mrow> <mi mathvariant="script">C</mi> <mo stretchy="false">(</mo> <mi>A</mi> <mo stretchy="false">)</mo> </mrow> </math></EquationSource> </InlineEquation>. In this work, we first present an integer constraint satisfaction problem for constructing a magic square of order <InlineEquation ID="IEq7"> <EquationSource Format="TEX">\( n \)</EquationSource> <EquationSource Format="MATHML"><math> <mi>n</mi> </math></EquationSource> </InlineEquation>. Nonetheless, the solution time of this problem grows exponentially as the order increases. To overcome this limitation, we also propose a fast approach that constructs magic squares depending on whether <InlineEquation ID="IEq8"> <EquationSource Format="TEX">\( n \)</EquationSource> <EquationSource Format="MATHML"><math> <mi>n</mi> </math></EquationSource> </InlineEquation> 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 70&#xa0;000 in less than 140 seconds, demonstrating its efficiency and scalability.</p>

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Constructing magic squares: an integer constraint satisfaction problem and a fast approach

  • João Vitor Pamplona,
  • Maria Eduarda Pinheiro,
  • Luiz-Rafael Santos

摘要

Magic squares are a fascinating mathematical challenge that has intrigued mathematicians for centuries. Given a positive (and possibly large) integer \( n \) n , one of the main challenges that still remains is to find, within a reasonable computational time, a magic square of order \( n \) n , that is, a square matrix of order \( n \) n with unique integers from \( a_{\min } \) a min to \( a_{\max } \) a max , such that the sum of each row, column, and diagonal equals a constant \( \mathcal {C}(A) \) C ( A ) . In this work, we first present an integer constraint satisfaction problem for constructing a magic square of order \( n \) n . Nonetheless, the solution time of this problem grows exponentially as the order increases. To overcome this limitation, we also propose a fast approach that constructs magic squares depending on whether \( n \) 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 70 000 in less than 140 seconds, demonstrating its efficiency and scalability.