File size: 814 Bytes
1ca0407
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Flat Littlewood polynomial of degree 69 (EinsteinArena flat-polynomials, MIT).

Score = max_{z in grid} |g(z)| / sqrt(71) over 10^6 equally spaced points of the unit circle (minimize),
exactly as the upstream verifier (np.poly1d, np.linspace(0, 2pi, 10^6)). Change: coefficients must be the
JSON integers 1/-1 (upstream cast to float first, so 1.0 and true were accepted)."""
import numpy as np

from run import Invalid, int_list


def check(inst, ans):
    n = inst["n_coeffs"]
    c = int_list(ans.get("coefficients"), n, -1, 1, "coefficients")
    if any(x == 0 for x in c):
        raise Invalid("coefficients must be +1 or -1")
    zs = np.exp(1j * np.linspace(0, 2 * np.pi, inst["grid"]))
    vals = np.abs(np.poly1d(np.array(c, dtype=np.float64))(zs))
    return float(np.max(vals) / np.sqrt(n + 1)), {}