day16.lib package

Submodules

day16.lib.cells module

Cell classes.

class day16.lib.cells.BackSlashCell(contents: str)[source]

Bases: Cell

A \ cell.

next_lasers(laser: Laser) list[Laser][source]

Lasers go diagonal mode.

class day16.lib.cells.Cell(contents: str)[source]

Bases: ABC

Abstract cell class.

CELL_TYPES: Dict[str, Type[Cell]] = {'-': <class 'day16.lib.cells.DashCell'>, '.': <class 'day16.lib.cells.DotCell'>, '/': <class 'day16.lib.cells.ForwardSlashCell'>, '\\': <class 'day16.lib.cells.BackSlashCell'>, '|': <class 'day16.lib.cells.PipeCell'>}
static construct(contents: str) Cell[source]

Construct proper cell from given contents.

contents: str
abstract next_lasers(laser: Laser) list[Laser][source]

Return next lasers given a laser entering this cell.

static register_cell_type(cell_contents: str) Callable[[type[Cell]], type[Cell]][source]

Registers a cell type to this factory.

class day16.lib.cells.DashCell(contents: str)[source]

Bases: Cell

A - cell.

next_lasers(laser: Laser) list[Laser][source]

Lasers must end up going east/west after passing through this cell.

class day16.lib.cells.DotCell(contents: str)[source]

Bases: Cell

A dot cell.

next_lasers(laser: Laser) list[Laser][source]

Lasers pass directly through this tile.

class day16.lib.cells.ForwardSlashCell(contents: str)[source]

Bases: Cell

A / cell.

next_lasers(laser: Laser) list[Laser][source]

Lasers go diagonal mode.

class day16.lib.cells.PipeCell(contents: str)[source]

Bases: Cell

A | cell.

next_lasers(laser: Laser) list[Laser][source]

Lasers must end up going north/south after passing through this cell.

day16.lib.direction module

Direction class.

class day16.lib.direction.Direction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Simple direction enum.

EAST = 1
NORTH = 0
SOUTH = 2
WEST = 3
offset(row: int, col: int) tuple[int, int][source]

Offset a row/col by our direction.

opposite() Direction[source]

Returns opposite direction.

day16.lib.laser module

laser instance class.

class day16.lib.laser.Laser(row: int, col: int, direction: Direction)[source]

Bases: object

Laser position + direction.

col: int
direction: Direction
row: int

day16.lib.parsers module

Parsers for input file.

day16.lib.parsers.get_input(path: str) World[source]

Read input file and return well formed :class:World.

day16.lib.world module

Well defined world classes.

class day16.lib.world.SolvedWorld(num_rows: int, num_cols: int)[source]

Bases: object

A solved world class, stores how many lasers are in each tile.

add_laser(laser: Laser) None[source]

Adds laser to cell.

already_solved(laser: Laser) bool[source]

Returns true if laser already calculated.

data: list[list[list[Laser]]]
num_energized() int[source]

Return number of energized cells.

class day16.lib.world.World(data: list[list[Cell]])[source]

Bases: object

The input world (mirrors/empty tiles).

data: list[list[Cell]]
is_oob(laser: Laser) bool[source]

True if laser is out of bounds.

num_cols: int
num_rows: int
solve(start_laser: Laser) SolvedWorld[source]

Solve our world.

Module contents

library modules for day16.