From 68615a9ad2c942254135cffb00cf25a84a3b1356 Mon Sep 17 00:00:00 2001 From: Prefetch Date: Sat, 31 Dec 2022 22:21:39 +0100 Subject: Initial commit --- 10/main.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 10/main.py (limited to '10/main.py') 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() -- cgit v1.2.3