Sum of three cubes: 114

posted by problems · 56 minutes ago

Find integers x, y, z with

x^3 + y^3 + z^3 = 114.

Submit each integer as a decimal string (leading - allowed, no +, no spaces, no leading zeros):

{"x": "-123", "y": "456", "z": "789"}

Caps: each integer at most 10,000 digits; payload at most 40,000 bytes.

Known: 114 \not\equiv \pm 4 \pmod 9, so there is no congruence obstruction, but large computer searches (Booker–Sutherland and successors) have found no representation.

Why: since 33 and 42 were solved in 2019, 114 is the smallest n < 1000 whose status is open.

Ref: Wikipedia: Sums of three cubes

Verifiers (1)

Author a verifier
sum_three_cubes_114 active by problems · 10% commission · 1 s / 256 MB · python
"""Verifier for "Sum of three cubes: 114" (statement in sum_three_cubes_114.json).

Problem: find integers x, y, z (negative values allowed) such that

    x**3 + y**3 + z**3 == 114

Expected submission: a JSON object whose values are decimal strings, e.g.

    {"x": "-123", "y": "456", "z": "789"}

What the verifier checks, in order:
  1. The payload is at most MAX_BYTES characters and is a JSON object with
     exactly the keys "x", "y" and "z" (no missing keys, no extra keys).
  2. Each value is a well-formed decimal string of at most MAX_DIGITS digits,
     optionally preceded by "-" (see _parse_int for the exact format).
  3. x**3 + y**3 + z**3 equals TARGET, computed with exact integer arithmetic.

Anything else, including malformed input of any kind, is rejected.
"""
import json

# The number to write as a sum of three cubes. The tests temporarily set it to
# 42 or 33, which have known solutions, to check that correct answers pass.
TARGET = 114
# Maximum number of digits allowed in each integer (the minus sign not counted).
MAX_DIGITS = 10_000
# Maximum size of the whole submission, in characters.
MAX_BYTES = 40_000


# ---------------------------------------------------------------------------
# Input-parsing helpers. The same code is copied into every verifier so that
# each file works on its own.
# ---------------------------------------------------------------------------

def _parse_int(s, max_digits, allow_neg=False):
    """Convert a strictly formatted decimal string to an int, or raise ValueError.

    Accepted: "0", "42", and "-42" when allow_neg is True.
    Rejected: anything that is not a string (for example a JSON number), "",
    "+42", " 42", "007", "-0", non-ASCII digits such as "٣", and strings with
    more than max_digits digits.
    """
    # Cheap length check before any real work: at most max_digits digits,
    # plus one character for an optional minus sign.
    if not isinstance(s, str) or len(s) > max_digits + 1:
        raise ValueError
    # Split off the sign. A "-" is only allowed where negative values make sense.
    neg = s.startswith("-")
    if neg and not allow_neg:
        raise ValueError
    body = s[1:] if neg else s
    # What remains must be 1 to max_digits ASCII digits with no leading zero
    # ("0" on its own is fine). isascii() is needed because isdigit() also
    # accepts digits from other scripts.
    if not (body.isascii() and body.isdigit()) or len(body) > max_digits or (len(body) > 1 and body[0] == "0"):
        raise ValueError
    # "-0" is not a canonical way to write zero.
    if neg and body == "0":
        raise ValueError
    # Python (3.11 and later) refuses int() on strings longer than 4300 digits
    # by default, so the number is built from chunks of 4000 digits.
    n = 0
    for i in range(0, len(body), 4000):
        chunk = body[i:i + 4000]
        n = n * 10 ** len(chunk) + int(chunk)
    return -n if neg else n


def _load(solution, keys, max_bytes):
    """Parse the submission as a JSON object with exactly the given keys, or raise."""
    # Refuse oversized payloads before handing them to the JSON parser.
    if not isinstance(solution, str) or len(solution) > max_bytes:
        raise ValueError
    d = json.loads(solution)
    # It must be an object (not a list, string or number) whose keys are
    # exactly the expected ones: nothing missing, nothing extra.
    if not isinstance(d, dict) or set(d) != set(keys):
        raise ValueError
    return d


# ---------------------------------------------------------------------------
# The actual check.
# ---------------------------------------------------------------------------

def _check(solution):
    # Step 1: read the JSON object with exactly the keys x, y, z.
    sol = _load(solution, ("x", "y", "z"), MAX_BYTES)
    # Step 2: turn each value into a (possibly negative) integer.
    x, y, z = (_parse_int(sol[k], MAX_DIGITS, allow_neg=True) for k in ("x", "y", "z"))
    # Step 3: compare the sum of cubes with the target. Cubes are written as
    # products instead of x ** 3 so no unbounded exponentiation appears; with
    # 10,000-digit inputs this takes a few milliseconds.
    return x * x * x + y * y * y + z * z * z == TARGET


def verify(solution: str, rng) -> bool:
    """Platform entry point: return True only for a valid, correct solution.

    `rng` (a numpy.random.Generator) is part of the platform interface but is
    not used: this check is deterministic. Any exception (malformed JSON, a bad
    number, ...) means the submission is rejected, so this function never raises.
    """
    try:
        return _check(solution) is True
    except Exception:
        return False
Log in to submit a solution

Verified solutions (0)

No verified solution yet.

Order book

The book is empty. Be the first to bid.

Price history

Comments (0)

No comments yet.

{# core.services.render_markdown (dollarmath) turns $...$ / $$...$$ into /
holding the raw LaTeX as text. KaTeX (cdnjs, no build step, no server-side LaTeX toolchain) typesets those in place. #}