conjecscore
Login Sign up

Leaderboard

liuguangxi
22012394
thyrgle
918140

Perfect Euler Brick

The Problem

An Euler brick, according to Wikipedia, is a rectangular cuboid whose edges and face diagonaals all have integer lengths.. To find an Euler Brick, one must satisfy the Diophantine system of equations: $$\begin{align*} a^2 + b^2 &= d^2 \\ a^2 + c^2 &= e^2 \\ b^2 + c^2 &= f^2 \end{align*}$$ that is, you must supply \(3\) integers \(a\), \(b\), and \(c\) (which correspond to the sides of the brick) such that \(a^2 + b^2\) is a square, \(a^2 + c^2\) is a square, and \(b^2 + c^2\) is also a square. A Perfect Euler Brick also requires that \(a^2 + b^2 + c^2\) is also a square. Although there are many examples of Euler Bricks, no example of a Perfect Euler Brick is known.

Submission Format

Please submit a CSV file that contains \(3\) numbers. These numbers correspond to \(a, b, c\) as described above. In order to be scored, you must submit a valid primitive Euler Brick, that is, \(a, b\) and \(c\) are all coprime. Let \(K = a^2 + b^2 + c^2\) and \(m = \lfloor \sqrt{K} \rfloor\) and \(M = \lceil \sqrt{K} \rceil\). Then the score is computed as: $$-\log\left(\frac{\min\{K - m^2, M^2 - K\}}{M^2 - m^2}\right) \times 10^6$$ The goal is to maximize this score function.

Score Implementation

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


from math import isqrt, gcd, log


async def score(nums: list[int]):
    # Ensure 3 integers are supplied.
    if len(nums) != 3:
        return None
    # Ensure numbers are between 1 and 10^100 
    for num in nums:
        if not (1 <= num <= 10 ** 100):
            return None

    a, b, c = nums

    # Ensure it is primitive
    if gcd(a, gcd(b, c)) > 1:
        return None

    # a^2 + b^2 = d^2
    ab = a ** 2 + b ** 2
    if isqrt(ab) ** 2 != ab:
        return None
    # a^2 + c^2 = e^2
    ac = a ** 2 + c ** 2
    if isqrt(ac) ** 2 != ac:
        return None
    # b^2 + c^2 = f^2
    bc = b ** 2 + c ** 2
    if isqrt(bc) ** 2 != bc:
        return None

    # How close to a square is a^2 + b^2 + c^2?
    abc = a ** 2 + b ** 2 + c ** 2
    sml_sqrt = isqrt(abc)
    big_sqr = (sml_sqrt + 1) ** 2
    sml_sqr = sml_sqrt ** 2
    interval = big_sqr - sml_sqr
    numer = min(abc - sml_sqr, big_sqr - abc)

    mil = 10 ** 6
    return int(-log(numer / interval) * mil)