This commit is contained in:
Jack Bond-Preston 2018-12-03 05:28:45 +00:00
parent e6bcbbf744
commit 290f8d2b4d
2 changed files with 1372 additions and 0 deletions

1327
aoc-3/inputs.txt Normal file

File diff suppressed because it is too large Load Diff

45
aoc-3/main.py Normal file
View File

@ -0,0 +1,45 @@
f = open("inputs.txt", "r")
inputs = f.read().split('\n')
claimed = {}
for s in inputs:
split = s.split(' ')
claimId = split[0]
coords = split[2].split(',')
x = int(coords[0])
y = int(coords[1][:-1])
size = split[3].split('x')
xSize = int(size[0])
ySize = int(size[1])
for i in range(x + 1, x + xSize + 1):
for j in range(y + 1, y + ySize + 1):
if (i, j) in claimed:
claimed[(i, j)].append(claimId)
else:
claimed[(i, j)] = [claimId]
overlap = 0
pureClaims = set()
impureClaims = set()
for key, value in claimed.items():
if len(value) > 1:
overlap += 1
for v in value:
pureClaims.discard(v)
impureClaims.add(v)
elif value[0] not in impureClaims:
pureClaims.add(value[0])
print(f"[Part 1] Overlapping squares: {overlap}")
if len(pureClaims) == 1:
print(f"[Part 2] Non-overlapping claim: {pureClaims.pop()}")