For part 1, it took way longer than necessary since I read the instructions over and over again. Gotta love AOC WOT. Part 2 was a PITA. I got stuck at the last 2 examples since I at the time did not find any clever way to determine which of the 2 outputs for '1' mapped to c and f. Since I already spent far too much time and effort, a try/except with ValueError (digits.index will fail if c and f are flipped wrong) will do for now. There is probably a more efficient and smart way to do this.
66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
import unittest
|
|
|
|
from solutions.day_08 import Solution
|
|
|
|
|
|
class Day08TestCase(unittest.TestCase):
|
|
def setUp(self):
|
|
self.solution = Solution()
|
|
self.puzzle_input = self.solution.parse_input(
|
|
"""
|
|
|
|
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
|
|
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
|
|
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg
|
|
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb
|
|
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea
|
|
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb
|
|
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe
|
|
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef
|
|
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb
|
|
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce
|
|
|
|
"""
|
|
)
|
|
|
|
def test_parse_puzzle_input(self):
|
|
data = """
|
|
be cfbegad | fdgacbe cefdb
|
|
edbfga begcd cbg | fcgedb cgb dgebacf
|
|
"""
|
|
assert self.solution.parse_input(data) == [
|
|
(["be", "cfbegad"], ["fdgacbe", "cefdb"]),
|
|
(["edbfga", "begcd", "cbg"], ["fcgedb", "cgb", "dgebacf"]),
|
|
]
|
|
|
|
def test_solve_first_part(self):
|
|
assert self.solution.solve(self.puzzle_input) == 26
|
|
|
|
def test_solve_second_part(self):
|
|
assert (
|
|
self.solution.solve_again(
|
|
[
|
|
(
|
|
[
|
|
"acedgfb",
|
|
"cdfbe",
|
|
"gcdfa",
|
|
"fbcad",
|
|
"dab",
|
|
"cefabd",
|
|
"cdfgeb",
|
|
"eafb",
|
|
"cagedb",
|
|
"ab",
|
|
],
|
|
["cdfeb", "fcadb", "cdfeb", "cdbaf"],
|
|
),
|
|
]
|
|
)
|
|
== 5353
|
|
)
|
|
assert self.solution.solve_again(self.puzzle_input) == 61229
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|