### re: AoC Day 3: No Matter How You Slice It VIEW POST

My messy af Python solutions. If I’m feeling energetic later today I’ll clean these up and write a Golang solution and benchmark the 2 :)

Part 1:

``````import re

def claims(input):
side = 1000
matrix = [["O" for x in range(side)] for y in range (side)]
idx = r'\d*(,)\d*'
dim = r'\d*(x)\d*'
cl = r'(#)\d*'
for claim in c:
claimant = int(re.search(cl, claim).group(0)[1:])
inidicies = [int(i) for i in re.search(idx, claim).group(0).split(',')]
dimensions = [int(i) for i in re.search(dim, claim).group(0).split('x')]
x = inidicies[0]
y = inidicies[1]
width = dimensions[0]
height = dimensions[1]
for _ in range(height):
for _ in range(width):
space = matrix[y][x]
if space == "O":
matrix[y][x] = claimant
else:
matrix[y][x] = "X"
x += 1
x = inidicies[0]
y += 1
check_overlap = 0
for x in matrix:
check_overlap += x.count("X")

return check_overlap

print(claims(open('input.txt', 'r')))
``````

Part 2

``````import re

def claims(input):
side = 1000
matrix = [["O" for x in range(side)] for y in range (side)]
idx = r'\d*(,)\d*'
dim = r'\d*(x)\d*'
cl = r'(#)\d*'
all_ids = set()
overlap_ids = set()
for claim in c:
claimant = int(re.search(cl, claim).group(0)[1:])
inidicies = [int(i) for i in re.search(idx, claim).group(0).split(',')]
dimensions = [int(i) for i in re.search(dim, claim).group(0).split('x')]
x = inidicies[0]
y = inidicies[1]
width = dimensions[0]
height = dimensions[1]
for _ in range(height):
for _ in range(width):
space = matrix[y][x]
if space == "O":
# first claim to this space
matrix[y][x] = claimant
elif space == 'X':
# claim overlaps with existing overlapped claim
else:
# claim overlaps with exactly one preexisting claim