Skip to content

Commit

Permalink
AoC2024.5 fix docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
loociano committed Dec 5, 2024
1 parent 66006b5 commit c52f211
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion aoc2024/src/day05/python/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def _is_valid(graph: RuleGraph, update: Sequence[int]) -> bool:


def _fix_update(graph: RuleGraph, incorrect_update: list[int]) -> Sequence[int]:
"""Fixes an incorrectly ordered update as per dependency graph."""

def cmp(a: int, b: int) -> int:
"""Compares two pages. If B depends on A then A goes before B."""
if b in graph[a]:
return -1
if a in graph[b]:
Expand All @@ -54,7 +57,10 @@ def cmp(a: int, b: int) -> int:


def sum_middle_pages(input: Sequence[str], from_correct_updates: bool = True) -> int:
"""Sums the middle page of all the valid updates."""
"""Sums the middle page of:
- If from_correct_updates=True, the valid updates.
- If from_correct_updates=False, from the fixed incorrectly ordered updates.
"""
breakline_num = list(input).index('')
graph = _generate_graph(input[:breakline_num])
updates = (list(map(int, input[i].split(',')))
Expand Down

0 comments on commit c52f211

Please sign in to comment.