Last active
December 14, 2022 14:30
-
-
Save CapacitorSet/8904ad75a5510cd2ae9331f4fa87aa9d to your computer and use it in GitHub Desktop.
Revisions
-
CapacitorSet revised this gist
Dec 14, 2022 . No changes.There are no files selected for viewing
-
CapacitorSet created this gist
Dec 14, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ solids = set() solids_y = dict() part1 = False def parse_coord(coord): x, y = coord.split(",") return int(x), int(y) with open("input") as file: for line in file: coords = [parse_coord(c) for c in line.rstrip().split(" -> ")] for i in range(len(coords) - 1): pair = sorted(coords[i:i+2]) for x in range(pair[0][0], pair[1][0]+1): for y in range(pair[0][1], pair[1][1]+1): solids.add((x, y)) if y in solids_y: solids_y[y].append(x) else: solids_y[y] = [x] grid_height = max([pos[1] for pos in solids]) if not part1: grid_height += 2 row = 0 old_row = set([500]) ret = 1 while row < grid_height - 1: row += 1 new_row = set(old_row) for item in old_row: new_row.add(item-1) new_row.add(item+1) if row in solids_y: for solid in solids_y[row]: if solid in new_row: new_row.remove(solid) ret += len(new_row) old_row = new_row print(ret)