Skip to content

Commit

Permalink
AoC 2024 day 14 docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
loociano committed Dec 14, 2024
1 parent fbd7d6f commit 8b2136d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions aoc2024/src/day14/python/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, position: Position, velocity: Velocity, world_size: WorldSize
self._height = world_size[1]

def move(self) -> None:
"""Moves robot from its position according to its constant velocity."""
self._x += self._dx
if self._x > self._width - 1:
self._x -= self._width # Wrap around right edge.
Expand Down Expand Up @@ -61,6 +62,7 @@ def get_quadrant(self) -> int:


def _parse(input: Sequence[str], world_size: WorldSize) -> tuple[Robot, ...]:
"""Parses the input. Each line represents a robot."""
robots = []
for line in input:
matches = re.match(r'p=(-?\d+),(-?\d+) v=(-?\d+),(-?\d+)', line)
Expand All @@ -74,6 +76,8 @@ def _parse(input: Sequence[str], world_size: WorldSize) -> tuple[Robot, ...]:

def get_safety_factor(input: Sequence[str], world_size: WorldSize = _DEFAULT_SIZE,
elapsed_seconds: int = 0) -> int:
"""Returns safety factor as the multiplication of robots per quadrant after a number of seconds.
Robots that end up between quadrants do not count towards safety factor."""
robots = _parse(input, world_size)
for _ in range(elapsed_seconds):
for robot in robots:
Expand Down

0 comments on commit 8b2136d

Please sign in to comment.