diff options
Diffstat (limited to '10')
-rwxr-xr-x | 10/main.py | 41 | ||||
-rwxr-xr-x | 10/test.py | 28 |
2 files changed, 69 insertions, 0 deletions
diff --git a/10/main.py b/10/main.py new file mode 100755 index 0000000..b2ec42c --- /dev/null +++ b/10/main.py @@ -0,0 +1,41 @@ +#!/usr/bin/python + + + +def play_round(old): + new = "" + + i = 0 + while i < len(old): + c = old[i] + + count = 0 + while i < len(old) and old[i] == c: + count += 1 + i += 1 + + new += str(count) + c + + return new + + + +def solve_partn(partn, string): + rounds = 40 if partn == 1 else 50 + for i in range(rounds): + string = play_round(string) + return len(string) + + + +def main(): + # My personal input string + string = "1113122113" + + print("Part 1 solution:", solve_partn(1, string)) # 360154 for me + print("Part 2 solution:", solve_partn(2, string)) # 5103798 for me + + + +if __name__ == "__main__": + main() diff --git a/10/test.py b/10/test.py new file mode 100755 index 0000000..a311b2e --- /dev/null +++ b/10/test.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +import unittest + +import main + + + +class ExamplesPart1(unittest.TestCase): + def test_example1(self): + self.assertEqual(main.play_round("1"), "11") + + def test_example2(self): + self.assertEqual(main.play_round("11"), "21") + + def test_example3(self): + self.assertEqual(main.play_round("21"), "1211") + + def test_example4(self): + self.assertEqual(main.play_round("1211"), "111221") + + def test_example5(self): + self.assertEqual(main.play_round("111221"), "312211") + + + +if __name__ == "__main__": + unittest.main() |