49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(38, "input18_test"),
|
|
(1926, "input18"),
|
|
],
|
|
[
|
|
(19986699, "input18"),
|
|
]
|
|
]
|
|
|
|
def get_safe_tiles(self, rows: int) -> int:
|
|
row = self.getInput()
|
|
safe_tiles = row.count(".")
|
|
for _ in range(rows - 1):
|
|
row = "." + row + "."
|
|
new_row = ""
|
|
for i in range(1, len(row) - 1):
|
|
if row[i - 1] == '^' and row[i] == '^' and row[i + 1] == '.':
|
|
new_row += "^"
|
|
elif row[i - 1] == '.' and row[i] == '^' and row[i + 1] == '^':
|
|
new_row += "^"
|
|
elif row[i - 1] == '^' and row[i] == '.' and row[i + 1] == '.':
|
|
new_row += "^"
|
|
elif row[i - 1] == '.' and row[i] == '.' and row[i + 1] == '^':
|
|
new_row += "^"
|
|
else:
|
|
new_row += "."
|
|
|
|
row = new_row
|
|
safe_tiles += row.count(".")
|
|
|
|
return safe_tiles
|
|
|
|
def part1(self) -> Any:
|
|
return self.get_safe_tiles(10 if self.is_test() else 40)
|
|
|
|
def part2(self) -> Any:
|
|
return self.get_safe_tiles(400_000)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2016, 18)
|
|
day.run(verbose=True)
|