33 lines
760 B
Python
33 lines
760 B
Python
import math
|
|
|
|
with open('updates.txt', 'r') as f:
|
|
updates = f.read().splitlines()
|
|
|
|
with open('rules.txt', 'r') as f:
|
|
rules = f.read().splitlines()
|
|
|
|
good_updates = []
|
|
|
|
middle_page_count = 0
|
|
|
|
for update in updates:
|
|
good_update = False
|
|
for rule in rules:
|
|
num_a, num_b = rule.split('|')
|
|
if num_a in update and num_b in update:
|
|
if update.find(num_a) < update.find(num_b):
|
|
good_update = True
|
|
|
|
else:
|
|
good_update = False
|
|
break
|
|
|
|
if good_update:
|
|
good_updates.append(update)
|
|
|
|
for update in good_updates:
|
|
update_parse = list(map(int, update.split(',')))
|
|
middle_page_count += update_parse[math.floor(len(update_parse) / 2)]
|
|
|
|
print(middle_page_count)
|