-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday10.py
49 lines (36 loc) · 876 Bytes
/
day10.py
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
42
43
44
45
46
47
48
#!/usr/bin/env python3
import sys
def look_and_say(line):
if not line:
return []
res = []
count = 1
prev = line[0]
for i in range(1, len(line)):
n = line[i]
if n != prev:
res.append(count)
res.append(prev)
count = 1
else:
count += 1
prev = n
res.append(count)
res.append(prev)
return res
def part1(lines):
res = [int(c,10) for c in lines[0]]
for _ in range(40):
res = look_and_say(res)
return len(res)
def part2(lines):
res = [int(c,10) for c in lines[0]]
for _ in range(50):
res = look_and_say(res)
return len(res)
def main():
lines = sys.stdin.read().strip().split("\n")
print("Part1: {}".format(part1(lines)))
print("Part2: {}".format(part2(lines)))
if __name__ == "__main__":
main()