day18
This commit is contained in:
parent
b6e46076bb
commit
b672c7cee2
48
day18.py
Normal file
48
day18.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
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)
|
||||||
1
inputs/input18
Normal file
1
inputs/input18
Normal file
@ -0,0 +1 @@
|
|||||||
|
^.^^^.^..^....^^....^^^^.^^.^...^^.^.^^.^^.^^..^.^...^.^..^.^^.^..^.....^^^.^.^^^..^^...^^^...^...^.
|
||||||
1
inputs/input18_test
Normal file
1
inputs/input18_test
Normal file
@ -0,0 +1 @@
|
|||||||
|
.^^.^.^^^^
|
||||||
Loading…
Reference in New Issue
Block a user