day03.lib package

Submodules

day03.lib.classes module

Day3 classes.

class day03.lib.classes.Gear(col: int, row: int, part_numbers: list[PartNumber] | None = None)[source]

Bases: object

Class representing a potential gear (* icon).

col: int
property gear_ratio: int

If we have exactly two parts, returns the gear ratio.

part_numbers: list[PartNumber] | None = None
row: int
class day03.lib.classes.Matrix(data: list[str])[source]

Bases: object

Represents the entire 2d array.

data: list[str]
filter_engine_parts(part_numbers: list[PartNumber]) list[PartNumber][source]

Return the legit part numbers.

find_gear_parts(gear: Gear, part_numbers: list[PartNumber]) list[PartNumber][source]

Returns a list of part_numbers that are touching a given gear.

get_gears(part_numbers: list[PartNumber]) list[Gear][source]

Retrieve gears from the matrix.

get_part_numbers() list[PartNumber][source]

Retrieve numbered words like 456 from the matrix.

is_engine_part(part_number: PartNumber) bool[source]

Return whether a part_number is an engine part by looking at its surroundings.

static is_engine_part_row(row: str) bool[source]

Returns if there is an engine part in this row.

property row_count: int

How many rows there are.

property row_size: int

How long each row is.

class day03.lib.classes.PartNumber(col: int, row: int, length: int, value: int)[source]

Bases: object

Class respresenting a potential part number, and its position.

col: int
property end_index: int

Returns the end column index of the number.

length: int
row: int
touching(col: int, row: int, row_size: int) bool[source]

Returns if a given coordinate is touching this PartNumber.

value: int

day03.lib.parsers module

Functions to parse from a file into well defined classes.

day03.lib.parsers.get_matrix(path: str) Matrix[source]

Convert text file to matrix.

Module contents

day03 libraries.