adventofcode-2018/03/solver01.py
2018-12-13 19:09:30 +01:00

34 lines
745 B
Python
Executable File

#!/usr/bin/python
import re
RE_LINE = re.compile('^#(\d+) @ (\d+),(\d+): (\d+)x(\d+)$')
plan = dict()
def read_input():
with open('input.txt', 'r') as f:
for line in f:
yield line.strip()
def hash_position(x, y):
return "{}x{}".format(x,y)
for claim in read_input():
m = RE_LINE.match(claim)
if not m:
raise Exception("unparsable input: {}".format(claim))
for x in range(int(m.group(4))):
for y in range(int(m.group(5))):
hash = hash_position(x+int(m.group(2)), y+int(m.group(3)))
if hash not in plan:
plan[hash] = []
plan[hash].append(int(m.group(1)))
overlap = [ k for k,v in plan.items() if len(v) > 1]
print(len(overlap))