diff options
author | Prefetch | 2022-12-31 22:21:39 +0100 |
---|---|---|
committer | Prefetch | 2022-12-31 22:21:39 +0100 |
commit | 68615a9ad2c942254135cffb00cf25a84a3b1356 (patch) | |
tree | 1ed3131f673207b2ef0bdaee3ee98bb68d6640ca /10/main.py |
Initial commit
Diffstat (limited to '10/main.py')
-rwxr-xr-x | 10/main.py | 41 |
1 files changed, 41 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() |