diff --git a/2015/10/code.py b/2015/10/code.py new file mode 100644 index 0000000..af5633f --- /dev/null +++ b/2015/10/code.py @@ -0,0 +1,40 @@ +import unittest + +from itertools import groupby + + +def say(number: str) -> str: + return "".join(f"{len(list(group))}{digit}" for digit, group in groupby(number)) + + +class TestCode(unittest.TestCase): + def test_say(self) -> None: + self.assertEqual(say(number="1"), "11") + self.assertEqual(say(number="11"), "21") + self.assertEqual(say(number="21"), "1211") + self.assertEqual(say(number="1211"), "111221") + self.assertEqual(say(number="111221"), "312211") + + +class TestPuzzles(unittest.TestCase): + def setUp(self) -> None: + with open("input.txt") as f: + self.number = f.read().splitlines()[0] + + def test_part_one(self) -> None: + solution = self.number + for _ in range(40): + solution = say(solution) + self.assertEqual( + len(solution), + 492982, + ) + + def test_part_two(self) -> None: + solution = self.number + for _ in range(50): + solution = say(solution) + self.assertEqual( + len(solution), + 6989950, + ) diff --git a/2015/10/input.txt b/2015/10/input.txt new file mode 100644 index 0000000..067b0ee --- /dev/null +++ b/2015/10/input.txt @@ -0,0 +1 @@ +1321131112