congrats, and big thanks for all your videos! see you next year ;-) having precomputed set of pin coordinates for multiple reuse and let intersection (&) do the heavy lifting ;-) def solve1(text): blocks = text.split("
") block_rows = blocks[0].splitlines() R = len(block_rows) C = len(block_rows[0]) locks = [] keys = [] for block in blocks: block_lines = block.splitlines() pins = set((r, c) for r in range(R) for c in range(C) if block_lines[r][c] == "#") if all(x == "#" for x in block_lines[0]): locks.append(pins) elif all(x == "#" for x in block_lines[-1]): keys.append(pins) else: assert False return len([1 for lock in locks for key in keys if len(lock & key) == 0])
The problem was disappointingly easy - pairwise zip all items and check for presence of (#,#), that is it. No need to preclasify things into locks / keys.
Thanks for all the interesting videos. Congrats on making the top 100!
Thanks for the videos and happy holidays!
congrats, and big thanks for all your videos! see you next year ;-)
having precomputed set of pin coordinates for multiple reuse and let intersection (&) do the heavy lifting ;-)
def solve1(text):
blocks = text.split("
")
block_rows = blocks[0].splitlines()
R = len(block_rows)
C = len(block_rows[0])
locks = []
keys = []
for block in blocks:
block_lines = block.splitlines()
pins = set((r, c) for r in range(R) for c in range(C) if block_lines[r][c] == "#")
if all(x == "#" for x in block_lines[0]):
locks.append(pins)
elif all(x == "#" for x in block_lines[-1]):
keys.append(pins)
else:
assert False
return len([1 for lock in locks for key in keys if len(lock & key) == 0])
bro do something about that cough, you have been coughing since day 16 or so... anyway great video as always
The problem was disappointingly easy - pairwise zip all items and check for presence of (#,#), that is it. No need to preclasify things into locks / keys.