44 lines
1002 B
Python
44 lines
1002 B
Python
|
#!/bin/python3
|
||
|
import sys
|
||
|
from pprint import pprint
|
||
|
|
||
|
input_f = "input" #sys.argv[1]
|
||
|
|
||
|
arr = []
|
||
|
|
||
|
with open(input_f) as file:
|
||
|
for line in file:
|
||
|
arr = list(line.rstrip('\n'))
|
||
|
#########################################
|
||
|
# #
|
||
|
# Part 1 #
|
||
|
# #
|
||
|
#########################################
|
||
|
sum = 0
|
||
|
for idx,x in enumerate(arr):
|
||
|
if idx != len(arr)-1:
|
||
|
if x == arr[idx+1]:
|
||
|
sum+=int(x)
|
||
|
else:
|
||
|
if x == arr[0]:
|
||
|
sum+=int(x)
|
||
|
|
||
|
print(sum)
|
||
|
|
||
|
#########################################
|
||
|
# #
|
||
|
# Part 2 #
|
||
|
# #
|
||
|
#########################################
|
||
|
|
||
|
sum=0
|
||
|
length=len(arr)
|
||
|
|
||
|
for idx,x in enumerate(arr):
|
||
|
if idx != length:
|
||
|
print(x,arr[(int(length/2)+idx) % length])
|
||
|
if x == arr[(int(length/2)+idx) % length]:
|
||
|
sum+=int(x)
|
||
|
|
||
|
print(sum)
|