Home > Magic Hexagons > Description

Magic Hexagons

Ends: 22 Mar 2026 15:00
Now: 26 Mar 2025 13:06

AZsPCs | Thoroughly Magic Hexagons | Description


Magic Hexagons

An n × n × n hexagonal grid, also called an order-n hexagonal grid, has three axes at 60-degree angles from each other. Each of these axes has 2n − 1 rows of hexagons parallel to it.


The 3 axes of a hexagonal grid
       


One of the 15 rows in an order-3 grid

Such a grid is called a magic hexagon if:

  • the cells of the grid contain sequential integers, one integer per cell, and
  • the cells of each of the 3(2n - 1) rows add up the same sum.

The common sum in a magic hexagon is called the magic constant.


An order-3 magic hexagon with integers from 1 to 19 and with magic constant 38

Note that an order-n magic hexagon with magic constant 0 must contain the integers from -3n(n - 1) / 2 to 3n(n - 1) / 2, but the inverse is not true — an order-n hexagon containing the integers from -3n(n - 1) / 2 to 3n(n - 1) / 2 is not necessarily magic.


Magic number = 0,
must contain integers -9 to 9
       

Contains integers -9 to 9,
need not be magic

The Contest

In this contest we are interested only in order-n hexagons containing the integers from −3n(n − 1) / 2 to 3n(n − 1) / 2. You are asked to create such a hexagonal grid for each value of n from 10 to 109, inclusive. Furthermore, you are to create grids that are as "close to magic" as possible.

The following calculation quantifies how "close to magic" a grid is:

Let ρi be the sum of the values in the ith row. Then your grid-score is Σ(ρi)2 / 2 + 1.

The grid-score measures the extent to which the grid fails to be "close to magic". Low values for grid-score are better than high scores. A magic hexagon has a grid-score of one.


How to Enter

Paste your solutions (that is, your hexagonal grids) into the appropriate box on the Submit page and click Submit Entry.

Encode each solution as a comma-delimited list of rows, where each row is a comma-delimited list of integers. Enclose each row in parentheses. For example, you would encode the grid above as follows:

(-9,1,8),(6,5,-4,-7),(3,-8,-3,9,-1),(2,4,0,-6),(-5,-2,7)

Include spaces and other white space (tabs, line breaks, etc.) anywhere you like – but not, of course, within an integer.

To submit more than one solution at a time, separate them with semicolons. Do not place a semicolon after the last solution.

Over the course of the contest, you may submit multiple solutions for the same grid size, but only your best-scoring grid for each n will count.

To help minimize the amount of storage consumed by the AZsPCs database, please do not submit a solution unless it improves on your previous submissions for that grid-size. However, you may submit as many solutions for n = 2 through 9 as you wish — the system validates such solutions and calculates their grid-scores, but does not store any information in the database.


The Contest Scoring System

The entrant with the highest "contest score" wins. Here's how we calculate your contest score:

  • For each of the 100 values of n we determine the "raw score", the grid-score for your best submission of that size grid.

  • For each of the 100 values of n, we compute the "subscore". We do this by dividing each n's raw score into the lowest raw score for that n across all entrants. Every subscore therefore has a value from 0 to 1.

  • Your contest score is the sum of your 100 subscores.

The highest contest score wins. If two entrants have the same contest score, we break the tie by giving preference to the entrant whose last improvement was submitted least recently.

Let's walk through a simplified example. Suppose we modify the contest by asking you to submit hexagonal grids for only three values of n: 10, 11 and 12. Further suppose that we have 3 entrants: Luciano, Plácido and José.

We begin by recording the grid-score for each hexagonal grid:

n = 10 n = 11 n = 12
Luciano 8,686 51,115 176,693
Plácido 2,797 53,259 472,521
José 4,371 27,645 734,472

We then calculate raw scores by adding 1 to each grid-score:

n = 10 n = 11 n = 12
Luciano 8,687 51,116 176,694
Plácido 2,798 53,260 472,522
José 4,372 27,646 734,473

Next, we note the lowest raw score for each value of n:

n = 10 n = 11 n = 12
Lowest Raw Score 2,798 27,646 176,694

Finally, we compute the subscores and contest score for each entrant:

n = 10 n = 11 n = 12 Contest Score
Luciano 2,798 / 8,687 = .322 27,646 / 51,116 = 0.541 176,694 / 176,694 = 1.000 1.863
Plácido 2,798 / 2,798 = 1.000 27,646 / 53,260 = .519 176,694 / 472,522 = .374 1.893
José 2,798 / 4,372 = .640 27,646 / 27,646 = 1.000 176,694 / 734,473 = .241 1.881

Plácido has the highest contest score and therefore is the winner.


Getting Your Questions Answered

First, check the FAQ section below. If you can't find the information you need there, send your question to the AZsPCs Forum. If your question is of a personal nature, and not of general interest, send an email directly to Al Zimmermann.


The AZsPCs Forum

If you think you might enter the contest, you should join the AZsPCs Forum. You can join either by sending a blank email here or by visiting the forum on groups.io. The AZsPCs Forum serves two purposes. First, it allows contestants to ask for clarifications to the rules. Be aware that sometimes these requests result in changes to the rules, and the first place those changes are announced is in the AZsPCs Forum. Second, the Forum allows contestants to interact with each other regarding programming techniques, results and anything else relevant to the contest.


Frequently Asked Questions

  • Can teams enter the contest?

    Yes. But a team can only be formed by those who have not already entered the contest as individuals. Once you enter as an individual, team membership is no longer open to you. Likewise, once you've joined a team you can't resign from it and start submitting grids on your own behalf.

    If you would like to form a team, please follow these instructions:

    • If they do not already exist, create individual accounts for each team member. Do not create a second account for any team member who already has one.

    • Let me know each team member's name and registered email address. It is important that no team member submit any entries to this contest until I notify you that the team has been created.

    • After I've created the team, team members can submit entries to the contest from their individual accounts. The contest engine automatically intercepts these entries and diverts them to the team account. The team is listed on the standings page.

    • Unless you are satisfied with the defaults, also let me know what team name and team location you would like to use on the standings page. Note that if all team members are from the same organization, the organization name can be included in the location, e.g., "Olaf Academy, Oslo, Norway".
      – For name, the default is a combination of your last names. For example, "Newton / Leibniz".
      – For location, the default is whatever seems reasonable to me, for example, "California" or "Germany" (remember, you can override whatever I choose).

    Note: Teams are contest-specific. Joining a team for this contest does not affect your participation in other contests.

  • May I write a program that submits entries by bypassing my browser?

    Yes.

  • May I programmatically download the standings page at regular intervals? How frequently would be reasonable?

    Yes, you may programmatically download the standings page at regular intervals. Please feel free to download it as often as once per second. If you want to download the standings page more frequently than that, please contact me first.

  • I've written a little program that helps a person generate solutions manually. May I distribute the executable to other contestants?

    No. This is a programming contest and writing useful tools is something one should be able to do for oneself. That alone would be sufficient reason to disallow the distribution of such tools, but consider also that you would be disadvantaging those who either don't hear about your tool or can't run your executable in their environment.

    However, if you are part of a team, you may share such tools with your teammates.

  • May I collude with an AI?

    Assuming your mean an Artificial Intelligence and not Al Zimmermann, the answer is yes.

  • What topics are appropriate for the AZsPCs Forum?

    With only one exception, if it's related to AZsPCs then it's fine to talk about it in the AZsPCs Forum. The exception is spoilers. Spoilers include:

      • specific solutions
      • detailed algorithms (yes, detailedness is subjective)

    If you are not sure if something would be considered a spoiler, ask me.

  • Why are hexagonal grids for n = 2 through n = 9 not stored in the database?

    So that you can use n = 2 through n = 9 for debugging.

  • Why do you divide by 2 and then add 1 to compute the grid-score?

    We divide by 2 because otherwise the score would be even, and smaller values are easier to work with.

    We add 1 to eliminate the need to ever divide by 0.

  • Why is this a 12-month contest, rather than 3 months like most of the other AZsPCs contests?

    It is not expected that anyone will work on this contest full-time for one year. There will  probably  possibly be a 3-month contest partway through the year. This 12-month contest is just something for the more  deranged  motivated members of the community to throw computing cycles at while waiting.