Skip to content

Instantly share code, notes, and snippets.

@josgraha
Last active August 29, 2015 14:24
Show Gist options
  • Save josgraha/da2a91d6cc4138c9cb58 to your computer and use it in GitHub Desktop.
Save josgraha/da2a91d6cc4138c9cb58 to your computer and use it in GitHub Desktop.
Magic Squares Problem

Description

Find a 4×4 magic square consisting of 16 different positive semiprimes less than 100. A semiprime is a positive integer with exactly two, not necessarily different, prime factors. (For example, both 21 = 3×7 and 25 = 52 are semiprimes.) In a magic square, the entries in each column, row, and major diagonal have the same sum (known as the magic sum). We want a magic square for which, in addition, the four center entries, the four corners, and each of the four quadrants also exhibit the same magic sum, making a total of 16 ways to get the magic sum. We want the square with the smallest magic sum for such a square. Present your answer as four rows of four integers each.

Hints

Primes up to 100

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97

Semiprimes up to 100

4, 6, 9, 10, 14, 15, 21, 22, 25, 26, 33, 34, 35, 38, 39, 46, 49, 51, 55, 57, 58, 62, 65, 69, 74, 77, 82, 85, 86, 87, 91, 93, 94, 95

Magic Square Example

| | | | sum --- | --- | --- | --- | --- | 8 | 1 | 6 | 15 | 3 | 5 | 7 | 15 | 4 | 9 | 2 | 15 sum | 15 | 15 | 15 | 15

References

Online Ecyclopedia of Integer Series, https://oeis.org/A001358

Solution

4x4 Magic Square

| | | | | sum --- | --- | --- | --- | --- | --- | | | | | x | | | | | x | | | | | x | | | | | x sum | x | x | x | x | x

Semiprimes (1-16)

A. Center Square

| | | sum --- | --- | --- | --- | | | | | | sum | | |

B. Top Right Quadrant

| | | sum --- | --- | --- | --- | | | | | | sum | | |

C. Top Left Quadrant

| | | sum --- | --- | --- | --- | | | | | | sum | | |

D. Bottom Right Quadrant

| | | sum --- | --- | --- | --- | | | | | | sum | | |

E. Bottom Left Quadrant

| | | sum --- | --- | --- | --- | | | | | | sum | | |

Smallest Magic Square

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment