Day 24: Lobby Layout¶
Classes:
|
Represent a hexagonal cell of the layout using cube coordinates. |
|
Enumerate the possible directions from a hexagonal cell. |
Functions:
|
Convert the |
|
Retrieve the next cell starting from |
|
Walk the |
|
Parse the input line. |
|
Represent the directions as a concatenated text. |
|
Count how many cells had to flip for the given |
Data:
Express a list of directions |
|
Express a single direction |
- class Cell(x: int, y: int, z: int)[source]¶
Represent a hexagonal cell of the layout using cube coordinates.
See https://www.redblobgames.com/grids/hexagons/.
Methods:
__init__
(x, y, z)Initialize with the given values.
Attributes:
X-coordinate (south-east, north-west)
Y-coordinate (south-west, north-east)
Z-coordinate (east, west)
- __init__(x: int, y: int, z: int) None [source]¶
Initialize with the given values.
- Requires
x + y + z == 0
- x: Final[int]¶
X-coordinate (south-east, north-west)
- y: Final[int]¶
Y-coordinate (south-west, north-east)
- z: Final[int]¶
Z-coordinate (east, west)
- cell_as_tuple(cell: Cell) Tuple[int, int, int] [source]¶
Convert the
cell
into a tuple of x, y and z coordinates.
- class Direction(value)[source]¶
Enumerate the possible directions from a hexagonal cell.
Attributes:
- EAST = 'e'¶
- SOUTH_EAST = 'se'¶
- SOUTH_WEST = 'sw'¶
- WEST = 'w'¶
- NORTH_WEST = 'nw'¶
- NORTH_EAST = 'ne'¶
- VALUE_TO_DIRECTION = {'e': Direction.EAST, 'ne': Direction.NORTH_EAST, 'nw': Direction.NORTH_WEST, 'se': Direction.SOUTH_EAST, 'sw': Direction.SOUTH_WEST, 'w': Direction.WEST}¶
- next_cell(cell: Cell, direction: Direction) Cell [source]¶
Retrieve the next cell starting from
cell
in thedirection
.
- follow_directions(start: Cell, directions: List[Direction]) Cell [source]¶
Walk the
directions
from thestart
.- Returns
The final
Cell
of the journey
- DIRECTIONS_RE = re.compile('^(se|sw|nw|ne|w|e)+\\Z')¶
Express a list of directions
- ONE_DIRECTION_RE = re.compile('(se|sw|nw|ne|w|e)')¶
Express a single direction
- parse_line(line: str) List[Direction] [source]¶
Parse the input line.
- Requires
len(line) > 0
⇒DIRECTIONS_RE.match(line)
- Ensures
stringify_directions(result) == line
len(line) == 0
⇒len(result) == 0