Yet again I got stuck in the common AOC trap: The example input worked, but not the actual input. 2 things got me stuck. > The size of a basin is the number of locations within the basin, including the low point. The example above has four basins. 1. I missed the obvious part to only check the low points. 2. Based on the example, I asumed that the adjacent locations would increase by one to count. This is wrong: What matters is that their height is a larger value. Way too long time for a simple problem. Never read puzzles sloppy.
37 lines
830 B
Python
37 lines
830 B
Python
import unittest
|
|
|
|
from solutions.day_09 import Solution
|
|
|
|
|
|
class Day09TestCase(unittest.TestCase):
|
|
def setUp(self):
|
|
self.solution = Solution()
|
|
self.puzzle_input = self.solution.parse_input(
|
|
"""
|
|
2199943210
|
|
3987894921
|
|
9856789892
|
|
8767896789
|
|
9899965678
|
|
"""
|
|
)
|
|
|
|
def test_parse_puzzle_input(self):
|
|
data = """
|
|
2199943210
|
|
3987894921
|
|
"""
|
|
assert self.solution.parse_input(data) == [
|
|
[2, 1, 9, 9, 9, 4, 3, 2, 1, 0],
|
|
[3, 9, 8, 7, 8, 9, 4, 9, 2, 1],
|
|
]
|
|
|
|
def test_solve_first_part(self):
|
|
assert self.solution.solve(self.puzzle_input) == 15
|
|
|
|
def test_solve_second_part(self):
|
|
assert self.solution.solve_again(self.puzzle_input) == 9 * 14 * 9 # 891684
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|