From a224ebc673ec2a61979185020e83e27e4e644bfa Mon Sep 17 00:00:00 2001 From: Ryan Reed Date: Sun, 12 Dec 2021 22:11:10 -0500 Subject: [PATCH] Minor cleanup --- puzzles/TEMPLATE_dayXX.py | 2 +- puzzles/day11.py | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/puzzles/TEMPLATE_dayXX.py b/puzzles/TEMPLATE_dayXX.py index 8b64a1f..7545b34 100644 --- a/puzzles/TEMPLATE_dayXX.py +++ b/puzzles/TEMPLATE_dayXX.py @@ -25,7 +25,7 @@ def part2(inputs: List[int]) -> int: def parse(inputs: str) -> List[int]: """Parse the input string""" - return [int(line) for line in inputs.split()] + return [line for line in inputs.split("\n")] def solve(path: str) -> Tuple[int, int]: diff --git a/puzzles/day11.py b/puzzles/day11.py index 10f5424..9cfed16 100644 --- a/puzzles/day11.py +++ b/puzzles/day11.py @@ -26,7 +26,6 @@ class School: def __init__(self, data: List[str]) -> None: self.parse(data) - self.synchronized_steps = [] def flash(self, octopus: Octopus) -> None: octopus.energy_level = 0 @@ -36,21 +35,17 @@ class School: def update(self, octopus: Octopus) -> None: if octopus.last_flash == self.step: - return None + return octopus.energy_level += 1 if octopus.energy_level == 10: self.flash(octopus) def update_neighbors(self, location: Tuple[int, int]) -> None: - min_row = 0 if location[0] == 0 else location[0] - 1 - min_col = 0 if location[1] == 0 else location[1] - 1 - max_row = ( - location[0] if location[0] == self.size["rows"] - 1 else location[0] + 1 - ) - max_col = ( - location[1] if location[1] == self.size["cols"] - 1 else location[1] + 1 - ) + min_row = 0 if not location[0] else location[0] - 1 + min_col = 0 if not location[1] else location[1] - 1 + max_row = location[0] if location[0] == self.size["rows"] - 1 else location[0] + 1 + max_col = location[1] if location[1] == self.size["cols"] - 1 else location[1] + 1 for row in range(min_row, max_row + 1): for col in range(min_col, max_col + 1): @@ -88,9 +83,7 @@ class School: self.update(octopus) if self.is_synchronized(): - break - - return step + return step @property def total_flashes(self) -> int: