Skip to content

Commit

Permalink
2024 - Day 5: Print Queue
Browse files Browse the repository at this point in the history
Fix merge error
  • Loading branch information
supertom01 committed Dec 15, 2024
1 parent 613b321 commit 8d85c42
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions 2024/day5.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from day_base import Day


def fix_updates(updates, rules):
comparator = functools.cmp_to_key(lambda a, b: -1 if (a, b) in rules else (1 if (b, a) in rules else 0))
def fix_updates(updates, comparator):
correct_updates = []
corrected_updates = []
for update in updates:
Expand Down Expand Up @@ -34,13 +33,15 @@ def parse_data(self):

def part_a(self):
updates, rules = self.parse_data()
correct_updates, _ = fix_updates(updates, rules)
comparator = functools.cmp_to_key(lambda a, b: -1 if (a, b) in rules else (1 if (b, a) in rules else 0))
correct_updates, _ = fix_updates(updates, comparator)

return sum(x[int(len(x) / 2)] for x in correct_updates)

def part_b(self) -> int:
updates, rules = self.parse_data()
_, corrected_updates = fix_updates(updates, rules)
comparator = functools.cmp_to_key(lambda a, b: -1 if (a, b) in rules else (1 if (b, a) in rules else 0))
_, corrected_updates = fix_updates(updates, comparator)
return sum(x[int(len(x) / 2)] for x in corrected_updates)

if __name__ == '__main__':
Expand Down

0 comments on commit 8d85c42

Please sign in to comment.