started 2025 day5 parts 1 & 2
This commit is contained in:
1 parent
4fe4802afc
commit
d5d846ab0c
12 files changed
+2927
No files matched your search
@@ -0,0 +1,69 @@
|
||||
INPUT_FILE = "input.txt"
|
||||
|
||||
# True for roll of paper
|
||||
floor: list[list[bool]] = [ [ c == '@' for c in line.strip() ] for line in open(INPUT_FILE, 'r').readlines() ]
|
||||
|
||||
class iVec2d:
|
||||
x: int
|
||||
y: int
|
||||
|
||||
def __init__(self, x: int, y: int):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
max_y = len(floor)
|
||||
max_x = len(floor[0])
|
||||
|
||||
min_y = 0
|
||||
min_x = 0
|
||||
|
||||
def count_neighbors(floor: list[list[bool]], pos: iVec2d) -> int:
|
||||
DIRECTIONS = [
|
||||
iVec2d(-1, -1),
|
||||
iVec2d(0, -1),
|
||||
iVec2d(1, -1),
|
||||
iVec2d(-1, 0),
|
||||
iVec2d(1, 0),
|
||||
iVec2d(-1, 1),
|
||||
iVec2d(0, 1),
|
||||
iVec2d(1, 1)
|
||||
]
|
||||
|
||||
neighbors = 0
|
||||
for direction in DIRECTIONS:
|
||||
dx, dy = direction.x, direction.y
|
||||
|
||||
new_x = pos.x + dx
|
||||
new_y = pos.y + dy
|
||||
|
||||
if new_x >= max_x or new_x < min_x:
|
||||
continue
|
||||
|
||||
if new_y >= max_y or new_y < min_y:
|
||||
continue
|
||||
|
||||
if floor[new_y][new_x]:
|
||||
neighbors += 1
|
||||
|
||||
return neighbors
|
||||
|
||||
moveable_rolls = 0
|
||||
for y in range(len(floor)):
|
||||
for x in range(len(floor[0])):
|
||||
|
||||
pos = iVec2d(x, y)
|
||||
|
||||
if floor[pos.y][pos.x]:
|
||||
if count_neighbors(floor, pos) < 4:
|
||||
moveable_rolls += 1
|
||||
print('x', end='')
|
||||
else:
|
||||
print('@', end='')
|
||||
else:
|
||||
print('.', end='')
|
||||
|
||||
print()
|
||||
|
||||
print(f'Moveable Rolls: {moveable_rolls}')
|
||||
|
||||
|
||||
Reference in new issue
Block a user