Day 12: Rain Risk¶
Input: list of actions Output: position, Manhattan distance
Classes:
|
Represent the facing orientation of the ship. |
|
Represent the current ferry position. |
Functions:
|
Split the puzzle input along the newlines. |
|
Execute a single |
|
Execute the instructions and return the final ship's position. |
- class Orientation(value)[source]¶
Represent the facing orientation of the ship.
Attributes:
- EAST = 0¶
- SOUTH = 1¶
- WEST = 2¶
- NORTH = 3¶
- class ShipPosition(horizontal: int, vertical: int, orientation: Orientation)[source]¶
Represent the current ferry position.
Attributes:
Position of the ship in horizontal direction
Position of the ship in vertical direction
Orientation of the ship
Methods:
__repr__
()Return repr(self).
__eq__
(other)Return self==value.
__init__
(horizontal, vertical, orientation)- horizontal: int¶
Position of the ship in horizontal direction
- vertical: int¶
Position of the ship in vertical direction
- orientation: Orientation¶
Orientation of the ship
- __eq__(other)¶
Return self==value.
- __init__(horizontal: int, vertical: int, orientation: Orientation) None ¶
- parse_input(puzzle_input: str) Lines [source]¶
Split the puzzle input along the newlines.
- Requires
re.fullmatch(r"[NSEWLRF][0-9]+(n[NSEWLRF][0-9]+)*", puzzle_input)
- Ensures
"n".join(result) == puzzle_input
- update_position(current_position: ShipPosition, move: str) ShipPosition [source]¶
Execute a single
move
oncurrent_position
and return a new position.- Requires
not (move[0] == "L" or move[0] == "R") or int(move[1:]) in [0, 90, 180, 270, 360]
re.match(r"^[NSEWLRF][0-9]+$", move)
- solve(puzzle_input: str) ShipPosition [source]¶
Execute the instructions and return the final ship’s position.
- Requires
re.match( r"^(([NSEWF][0-9]+)|([LR](0|90|180|270|360)))" r"(\n(([NSEWF][0-9]+)|([LR](0|90|180|270|360))))*\Z", puzzle_input, )