Home > Nearly Magic Hexagons > Description

Nearly Magic Hexagons

Ends: 17 May 2025 16:00
Now: 21 Feb 2025 12:11

AZsPCs | Nearly Magic Hexagons | Description

The Elevator Pitch

A magic hexagon is similar to a magic square in that the values in each of its rows add up to the same "magic constant". In this contest you are asked, for various values of n, to create an order-n magic hexagon — or, if you cannot, then to create one that is "nearly" magic.


The Deep Dive

A regular hexagonal grid has three axes at 60° angles from each other. In an order-n grid, each of these axes has 2n-1 rows of hexagons that are parallel to it.


The 3 axes of a hexagonal grid
       

One of the 15 rows in an order-3 grid


For this contest, we are interested only in regular hexagonal grids whose cells are filled with successive integers starting with 1. Such a grid, if the sum of the numbers in each of the 3(2n-1) rows is the same, is called a magic hexagon.


A magic order-3 hexagon — each row's cells sum to 38
       

A non-magic order-3 hexagon

Sadly, there are only finitely many values of n for which an order-n magic hexagon exists. In this contest you will try to arrange the numbers in each of 100 grids (specifically, of orders 4 through 103) so that the row-sums in each grid are as nearly equal as possible. To evaluate how well you do, we use an objective scoring function (described in the next section).


The Hexagon Scoring Function

This section explains how to calculate the score for an individual hexagon. The calculation is roughly equivalent to taking the standard deviation of the grid's 3(2n-1) row sums.

  • First, pre-compute the following values. They depend only on n and not on the values in your grid:
    • The number of cells in your grid (cells-count) = 3n(n − 1) + 1
    • The sum of the cells in your grid (cells-sum) = cells-count × (cells-count + 1) / 2
    • The number of rows parallel to each axis (rows-per-axis) = 2n − 1

  • Second, compute the following for each row in your grid:
    • The sum of the cells in the row (row-sum)
    • The score for each row (row-score) = (row-sum × rows-per-axiscells-sum)2 / rows-per-axis

  • Third and final, the score for the grid (grid-score) = the sum of all row-scores divided by 2

The grid-score measures the extent to which the grid fails to be magic. Low values are better. A magic hexagon (such as the one above) has a score of zero.


The Contest

Submit your best grid for each grid size from n = 4 to n = 103 inclusive.

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


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 cell values. Enclose each row in parentheses.

For example, you would encode this grid

         

as follows:

(4,8,3),(9,16,15,12),(2,13,18,17,6),(5,14,19,11),(1,10,7)

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

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

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 and n = 3 as you wish — the system validates them, as it does all submissions, but does not store them 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 identify your best hexagonal grid (that is, the one for which the row sums are most nearly equal). Your "raw score" for that n is the score returned by the hexagon scoring function described above.

  • For each of the 100 values of n, we compute its "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. (If numerator and denominator are both zero, then, by fiat, the quotient is 1.)

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

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: 4, 5 and 6. Further suppose that we have 3 entrants: Penn, Teller and Merlin.

We begin by recording the score for each hexagonal grid:

n = 4 n = 5 n = 6
Penn 8,687 51,116 176,694
Teller 2,798 53,260 472,522
Merlin 4,372 27,646 734,473

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

n = 4 n = 5 n = 6
Lowest Raw Score 2,798 27,646 176,694

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

n = 4 n = 5 n = 6 Contest Score
Penn 2,798 / 8,687 = .322 27,646 / 51,116 = 0.541 176,694 / 176,694 = 1.000 1.863
Teller 2,798 / 2,798 = 1.000 27,646 / 53,260 = .519 176,694 / 472,522 = .374 1.893
Merlin 2,798 / 4,372 = .640 27,646 / 27,646 = 1.000 176,694 / 734,473 = .241 1.881

Teller 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 the smallest geographic entity containing all team member locations. For example, "Western Europe".

    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.

  • 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 and n = 3 never stored in the database?

    So that you can use n = 2 and n = 3 for debugging.

  • 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 intended to be something for the more highly  deranged  motivated members of the community to throw computing cycles at while waiting.