diff --git a/day18.py b/day18.py new file mode 100644 index 0000000..0927e50 --- /dev/null +++ b/day18.py @@ -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) diff --git a/inputs/input18 b/inputs/input18 new file mode 100644 index 0000000..19f6948 --- /dev/null +++ b/inputs/input18 @@ -0,0 +1 @@ +^.^^^.^..^....^^....^^^^.^^.^...^^.^.^^.^^.^^..^.^...^.^..^.^^.^..^.....^^^.^.^^^..^^...^^^...^...^. diff --git a/inputs/input18_test b/inputs/input18_test new file mode 100644 index 0000000..235ef50 --- /dev/null +++ b/inputs/input18_test @@ -0,0 +1 @@ +.^^.^.^^^^ \ No newline at end of file