25 lines
335 B
Python
25 lines
335 B
Python
from collections import deque
|
|
|
|
with open('data01.txt') as f:
|
|
data = f.read().strip()
|
|
|
|
|
|
d = deque(data)
|
|
total = 0
|
|
|
|
'''
|
|
#part 1
|
|
for i in range(len(data)):
|
|
if d[0] == d[1]:
|
|
total += int(d[0])
|
|
d.rotate()
|
|
'''
|
|
|
|
# part 2
|
|
half = len(data) // 2
|
|
for i in range(len(data)):
|
|
if d[0] == d[half]:
|
|
total += int(d[0])
|
|
d.rotate()
|
|
|
|
print(total) |