conjecscore
Login Sign up

Leaderboard

Magic Square of Squares

The Problem

The Magic Square of Squares Problem asks if there is a \(3\times3\) square with distinct square integers such that the rows, columns, and diagonals of the square all sum to the same value.

Submission Format

Please submit a CSV file that contains \(9\) numbers in the range \(1\) to \(10^{20}\). The order indicates which number appears in which cell, where the top left corner is the first number of the CSV and the bottom right corner is the last number of the CSV. The numbers you submit will each be squared and then the score will be computed. For your submission to be accepted, all numbers must be distinct and \(\geq 1\). If any of these two criterion are not satisfied, the entry will be rejected.

For scoring, the sum of each column, row, and diagonal is computed. Thus, we get a collection of numbers, call them \(\mathcal{D}\). Let the submitted entries be denoted \(\mathcal{I}\). Then the goal is to minimize the score function: $$\mathsf{score}(\mathcal{I}) := \frac{\max\mathcal{D} - \min\mathcal{D}}{\log(\max\mathcal{D})\mathsf{stddev}(\mathcal{I})}$$

Score Implementation

The following is a Python implementation of the score function to help you get started.


from math import log
from statistics import pstdev


def score(square: list[int]):
    # Ensure there are 9 entries
    if len(square) != 9:
        return None
    # Ensure there are distinct elements.
    if len(set(square)) != len(square):
        return None
    # Check if they are all squares.
    for entry in square:
        if entry <= 0 or entry >= 10 ** 20:
            return None

    std = pstdev(square)
    square = [x ** 2 for x in square]

    sums = []
    # Compute the score
    # Compute rows:
    sums.append(square[0] + square[1] + square[2])
    sums.append(square[3] + square[4] + square[5])
    sums.append(square[6] + square[7] + square[8])
    # Compute columns:
    sums.append(square[0] + square[3] + square[6])
    sums.append(square[1] + square[4] + square[7])
    sums.append(square[2] + square[5] + square[8])
    # Compute diagonals:
    sums.append(square[0] + square[4] + square[8])
    sums.append(square[6] + square[4] + square[2])

    M = max(sums)
    m = min(sums)
    result = (M - m) * (1 / (log(M) * std))
    return int(result * 10 ** 6)