You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
700 B
Python
28 lines
700 B
Python
6 years ago
|
#!/usr/bin/env python3
|
||
|
|
||
|
from pprint import pprint
|
||
|
|
||
|
with open('input.txt', 'r') as f:
|
||
|
coords = [x.strip().split(', ') for x in f.readlines()]
|
||
|
coords = [tuple(map(lambda y: int(y), x)) for x in coords]
|
||
|
|
||
|
# print(coords)
|
||
|
|
||
|
def distance(p1, p2):
|
||
|
"""Manhattan distance"""
|
||
|
return abs(p2[0] - p1[0]) + abs(p2[1] - p1[1])
|
||
|
|
||
|
min_x = min([x[0] for x in coords])
|
||
|
max_x = max([x[0] for x in coords])
|
||
|
min_y = min([x[1] for x in coords])
|
||
|
max_y = max([x[1] for x in coords])
|
||
|
|
||
|
res = 0
|
||
|
for x in range(min_x, max_x + 1):
|
||
|
for y in range(min_y, max_y + 1):
|
||
|
point = (x, y)
|
||
|
dist_sum = sum([distance(x, point) for x in coords])
|
||
|
if dist_sum < 10000:
|
||
|
res += 1
|
||
|
|
||
|
print(res)
|