day19.lib package
Submodules
day19.lib.classes module
well defined classes for day19.
- class day19.lib.classes.Comparator(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
StrEnum
Well defined comparators
<
and>
.- GreaterThan = '>'
- LessThan = '<'
- class day19.lib.classes.Component(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
StrEnum
A well defined component inside a part.
- A = 'a'
- M = 'm'
- S = 's'
- X = 'x'
- class day19.lib.classes.Condition(component: Component, sign: Comparator, value: int)[source]
Bases:
object
A condition for a part to succeed/fail.
- process_part(part: Part) bool [source]
Checks a part to see if it matches our condition.
- Parameters:
part (Part) – part to check
- Raises:
AssertionError – if component/sign are unsupported
- Returns:
True if the part passes our condition.
- Return type:
bool
- process_part_range(part_range: PartRange) tuple[PartRange | None, PartRange | None] [source]
Splits a part range based on success/fail.
- sign: Comparator
- value: int
- class day19.lib.classes.Part(x: int, m: int, a: int, s: int)[source]
Bases:
object
Well defined part with x,m,a,s values.
- a: int
- clone_modify(component: Component, value: int) Part [source]
Clones this part and modifies one component.
- m: int
- property rating: int
Returns rating of part (sum of xmas).
- s: int
- x: int
- class day19.lib.classes.PartRange(min_values: Part, max_values: Part)[source]
Bases:
object
A range of parts (min/max) based on component values.
- split(component: Component, split_value: int) tuple[PartRange | None, PartRange | None] [source]
Split a partrange in two, using a chosen component and splitvalue.
In the case that our range falls on one whole side, we return None. E.g. range = 0-100; split == 200 -> return [(0-100), None] range = 100-200; split == 50 -> return [None, (100-200)] range = 100-200, split == 150 -> return [(100-150), (150-200)]
- class day19.lib.classes.PartRangeDest(part_range: PartRange, destination: str)[source]
Bases:
object
Combinatoin of partrange and a destination workflow.
- destination: str
- class day19.lib.classes.Rule(destination: str, condition: Condition | None = None)[source]
Bases:
object
A Rule consists of a condition + destination.
- destination: str
- process_part(part: Part) str | None [source]
Processes a part.
Returns next workflow if successful, or None if we failed this rule
- process_part_range(part_range: PartRange) tuple[PartRangeDest | None, PartRange | None] [source]
Processes a PartRange.
Returns next workflow and partrange for succeeding parts. Returns the remainder partrange that failed.
- Parameters:
part_range (PartRange) – base partrange.
- Returns:
success, fail
- Return type:
tuple[Optional[PartRangeDest], Optional[PartRange]]
- class day19.lib.classes.Workflow(name: str, rules: list[Rule])[source]
Bases:
object
The name of the workflow + a bunch of rules for parts to follow.
- name: str
- process_part_range(part_range: PartRange) list[PartRangeDest] [source]
Follow rule list, splitting off PartRanges.
Each success has to branch off. Each failure continues down the chain.
day19.lib.parsers module
functions to create classes from pure text.
Module contents
Library modules for part19.