[py] Port 2017_01

This commit is contained in:
Joscha 2022-12-06 19:34:50 +01:00
parent beee256111
commit 21f671daed
3 changed files with 36 additions and 37 deletions

34
py/aoc/y2017/d01.py Normal file
View file

@ -0,0 +1,34 @@
def load_line(inputstr):
return list(map(int, inputstr[:-1]))
# PART 1
def sum_matching(digits):
offset = digits[1:] + digits
total = 0
for x, y in zip(digits, offset):
if x == y:
total += x
return total
# PART 2
def sum_matching_2(digits):
offset = digits[len(digits) // 2 :] + digits
total = 0
for x, y in zip(digits, offset):
if x == y:
total += x
return total
def solve(inputstr):
digits = load_line(inputstr)
total = sum_matching(digits)
print(f"Part 1: {total}")
total_2 = sum_matching_2(digits)
print(f"Part 2: {total_2}")