#!/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()