Some checks reported errors
continuous-integration/drone/push Build encountered an error
57 lines
No EOL
2 KiB
Python
57 lines
No EOL
2 KiB
Python
#!/usr/bin/env python
|
|
# 2025 - Advent Of Code 4 part 2
|
|
|
|
# file = 'input_example.txt'
|
|
file = 'input.txt'
|
|
|
|
# pylint: disable=consider-using-with
|
|
input_lines = [list(line.strip('\n')) for line in open(file, encoding="utf-8")]
|
|
MAX_X = len(input_lines[0])
|
|
MAX_Y = len(input_lines)
|
|
|
|
for pos_y in range(0, MAX_Y):
|
|
for pos_x in range(0, MAX_X):
|
|
print(input_lines[pos_y][pos_x], end='')
|
|
print()
|
|
print()
|
|
|
|
total_removed = 0
|
|
accessible = 1
|
|
while accessible != 0:
|
|
new_grid = [[input_lines[y][x] for x in range(MAX_X)] for y in range(MAX_Y)]
|
|
accessible = 0
|
|
for pos_y in range(0, MAX_Y):
|
|
for pos_x in range(0, MAX_X):
|
|
if input_lines[pos_y][pos_x] == '@':
|
|
rolls = 0
|
|
if pos_y > 0 and pos_x > 0 and input_lines[pos_y-1][pos_x-1] == '@':
|
|
rolls += 1
|
|
if pos_y > 0 and input_lines[pos_y-1][pos_x] == '@':
|
|
rolls += 1
|
|
if pos_y > 0 and pos_x < MAX_X - 1 and input_lines[pos_y-1][pos_x+1] == '@':
|
|
rolls += 1
|
|
if pos_x > 0 and input_lines[pos_y][pos_x-1] == '@':
|
|
rolls += 1
|
|
if pos_x < MAX_X - 1 and input_lines[pos_y][pos_x+1] == '@':
|
|
rolls += 1
|
|
if pos_y < MAX_Y - 1 and pos_x > 0 and input_lines[pos_y+1][pos_x-1] == '@':
|
|
rolls += 1
|
|
if pos_y < MAX_Y - 1 and input_lines[pos_y+1][pos_x] == '@':
|
|
rolls += 1
|
|
if pos_y < MAX_Y - 1 and pos_x < MAX_X - 1 and input_lines[pos_y+1][pos_x+1] == '@':
|
|
rolls += 1
|
|
|
|
if rolls < 4:
|
|
accessible += 1
|
|
new_grid[pos_y][pos_x] = 'x'
|
|
else:
|
|
new_grid[pos_y][pos_x] = input_lines[pos_y][pos_x]
|
|
|
|
# for pos_y in range(0, MAX_Y):
|
|
# for pos_x in range(0, MAX_X):
|
|
# print(input_lines[pos_y][pos_x], end='')
|
|
# print()
|
|
input_lines = new_grid.copy()
|
|
total_removed += accessible
|
|
|
|
print(total_removed) |