diff --git a/2021-python/solutions/day_06.py b/2021-python/solutions/day_06.py index d8d160c..31f2ea2 100644 --- a/2021-python/solutions/day_06.py +++ b/2021-python/solutions/day_06.py @@ -1,4 +1,5 @@ from solutions import BaseSolution +from collections import Counter, deque class Solution(BaseSolution): @@ -17,12 +18,15 @@ class Solution(BaseSolution): return self._produce(puzzle_input, 256) def _produce(self, puzzle_input, tf): - f = [*puzzle_input] - for _ in range(tf): - n = [8 for __ in range(sum(x <= 0 and x % 7 == 0 for x in f))] - f = list(map(lambda x: x - 1, f)) - f.extend(n) - return len(f) + f = Counter(puzzle_input) + s = deque([0] * 9) + for i in range(9): + s[i] = f[i] + for _d in range(tf): + e = s.popleft() + s[6] += e + s.append(e) + return sum(s) if __name__ == "__main__": diff --git a/2021-python/tests/test_day_06.py b/2021-python/tests/test_day_06.py index 7b4fd3d..d6417cb 100644 --- a/2021-python/tests/test_day_06.py +++ b/2021-python/tests/test_day_06.py @@ -21,8 +21,8 @@ class Day06TestCase(unittest.TestCase): def test_solve_first_part(self): assert self.solution.solve(self.puzzle_input) == 5934 - # def test_solve_second_part(self): - # assert self.solution.solve_again(self.puzzle_input) == 26984457539 + def test_solve_second_part(self): + assert self.solution.solve_again(self.puzzle_input) == 26984457539 if __name__ == "__main__":