day21.lib package

Submodules

day21.lib.classes module

classes for day21.

class day21.lib.classes.BaseDistanceMaze[source]

Bases: ABC

Abstract distance maze.

abstract calc_steps(remainder: int) int[source]

Calculate steps.

Matches remainder == 1 or remainder == 0 When modulo’ing by 2

abstract overlay(maze: Maze) str[source]

Overlays on top of a maze.

class day21.lib.classes.DistanceMaze(num_rows: int, num_cols: int)[source]

Bases: BaseDistanceMaze

Distance Maze == Maze.size.

calc_steps(remainder: int) int[source]

Calculate steps, based on odd/even steps.

centre_cell(row: int, col: int) bool[source]

Returns true if coordinate is the centre cell of the maze.

grid: list[list[int]]
int_to_str(value: int) str[source]

Convert integert to string.

is_complete() bool[source]

Returns true if all cells are filled.

is_oob(position: Position) bool[source]

True if position is out of bounds.

num_cols: int
num_rows: int
overlay(maze: Maze) str[source]

Overlay this distance_maze on a maze.

class day21.lib.classes.DistanceMazes(num_rows: int, num_cols: int)[source]

Bases: BaseDistanceMaze

An array of distance mazes, able to extend infinitely.

calc_steps(remainder: int) int[source]

Calculate steps given parity.

cols_per_maze: int
get_big_grid(position: Position) DistanceMaze[source]

Big grid coordinate.

get_split_pos(position: Position) tuple[Position, Position][source]

Split global position.

Into big map and small map positions.

Parameters:

position (Position) – global position

Returns:

big coord, small coord

Return type:

tuple[Position, Position]

grid: dict[Position, DistanceMaze]
overlay(maze: Maze) str[source]

Overlay our gigamap onto a maze.

rows_per_maze: int
class day21.lib.classes.GiantNodeParser(distance_mazes: DistanceMazes, nodes_to_edge: int)[source]

Bases: object

Convert from mazes to giant nodes.

distance_mazes: DistanceMazes
edge_dist: int
full_edge_dist: int
get_node(node_type: GiantNodeType) DistanceMaze[source]

Returns a giant node given its type.

get_node_count(node_type: GiantNodeType) int[source]

Returns how many of the giant node are required.

class day21.lib.classes.GiantNodeType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

A bunch of giant node types.

turn each “maze” into a node type. assume parity == EVEN e.g. 9 x 9 maze matrix mazes_center_to_bottom == 9 //2 == 4

BIG -> mazes_center_to_bottom - 1 == 3 SMALL -> mazes_center_to_bottom == 4 FULL_EVEN -> (mazes_center_to_bottom-1) ^2 == 9 FULL_ODD -> mazes_center_to_bottom^2 == 16

EAST_TIP = 5
FULL_EVEN = 0
FULL_ODD = 1
NORTH_EAST_BIG = 3
NORTH_EAST_SMALL = 4
NORTH_TIP = 2
NORTH_WEST_BIG = 12
NORTH_WEST_SMALL = 13
SOUTH_EAST_BIG = 6
SOUTH_EAST_SMALL = 7
SOUTH_TIP = 8
SOUTH_WEST_BIG = 9
SOUTH_WEST_SMALL = 10
WEST_TIP = 11
class day21.lib.classes.Maze(data: list[str])[source]

Bases: object

2d grid of items.

grid: list[str]
num_cols: int
num_rows: int
class day21.lib.classes.Position(row: int, col: int)[source]

Bases: object

Simple 2d vector.

It implements an unsafe hash since PositionDist inherits from this.

col: int
row: int
class day21.lib.classes.PositionDist(row: int, col: int, *, distance: int)[source]

Bases: Position

Position + distance.

distance: int
replace(row: int | None = None, col: int | None = None, distance: int | None = None) PositionDist[source]

Return a copy with given args changed.

Distance will +1 if not supplied

day21.lib.parsers module

Parsing code for day21.

day21.lib.parsers.parse_maze(filename: str) tuple[Position, Maze][source]

Returns a well defined Maze class.

Module contents

Library modules for day21.