2024/day5/part2.py

24 lines
733 B
Python
Executable File

#!/usr/bin/env python
from common import condense_page_orders, get_middle_page, parse, update_is_correct
def reorder(incorrect_update: tuple[int, ...], not_before, not_after) -> tuple[int, ...]:
return tuple()
def solve(input: tuple[list[tuple[int, int]], list[tuple[int, ...]]]) -> int:
raw_page_orders, updates = input
not_before, not_after = condense_page_orders(raw_page_orders)
incorrect_updates = filter(lambda u: not update_is_correct(u, not_before, not_after), updates)
middle_pages = [map(get_middle_page, sorted(incorrect_updates, key=lambda x: reorder(x, not_before, not_after)))]
return sum(middle_pages)
def main():
print(solve(parse("input")))
if __name__ == "__main__":
main()