advent/2017/day01.py

25 lines
335 B
Python
Raw Normal View History

2017-12-14 00:48:23 +00:00
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)