blob: b2ec42ce496c779cae5c82ec8822bbb6f6b05ba7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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()
|