Read the checking program (59 lines of Python)
"""Check distinct grid points have no two equal distances from any chosen point."""
import json
import sys
MAX_BYTES = 12608
GRID = 64
DIMENSION = 2
MAX_POINTS = 1576
def read_points(data):
lines = data.splitlines()
if not 1 <= len(lines) <= MAX_POINTS:
raise ValueError("The submission has the wrong number of points.")
points = []
for line in lines:
tokens = line.split()
if len(tokens) != DIMENSION:
raise ValueError("Each point must have exactly the specified number of coordinates.")
if any(len(t) > len(str(GRID - 1)) or not t.isdigit() for t in tokens):
raise ValueError("Coordinates must be nonnegative decimal integers within the grid.")
point = tuple(map(int, tokens))
if any(x >= GRID for x in point):
raise ValueError("A coordinate is outside the grid.")
points.append(point)
if len(set(points)) != len(points):
raise ValueError("The same point occurs more than once.")
return points
def verify(data):
points = read_points(data)
# Two equal squared distances from one point are exactly a forbidden triple.
for x, y in points:
distances = set()
for a, b in points:
distance = (x - a) ** 2 + (y - b) ** 2
if distance in distances:
raise ValueError("Two points are equally far from a third point.")
distances.add(distance)
return len(points)
def main():
data = sys.stdin.buffer.read(MAX_BYTES + 1)
try:
if len(data) > MAX_BYTES:
raise ValueError("Submission exceeds the byte limit.")
if not data.isascii() or any(c < 32 and c not in (9, 10, 13) for c in data):
raise ValueError("Use plain ASCII text.")
score = verify(data)
except ValueError as error:
result = {"valid": False, "score": None, "message": str(error)}
else:
result = {"valid": True, "score": score, "message": "The construction is valid."}
print(json.dumps(result, separators=(",", ":")))
if __name__ == "__main__":
main()