day20.lib package
Submodules
day20.lib.classes module
Classes for day20.
- class day20.lib.classes.BaseModule(name: str, outputs: list[str])[source]
Bases:
ABC
Abstract base module.
- add_to_graph(dot: Digraph) None [source]
Adds edges only to the graph. inheritors need to handle their repr.
- handle_pulse(input: str, pulse: Pulse) list[PulseTarget] [source]
Keep track of lows/highs through all modules.
- name: str
- num_high: int = 0
- num_low: int = 0
- outputs: list[str]
- class day20.lib.classes.BroadcastModule(name: str, outputs: list[str])[source]
Bases:
BaseModule
Broadcasts to all outputs.
- handle_pulse(input: str, pulse: Pulse) list[PulseTarget] [source]
Broadcasts to all outputs immediately.
- class day20.lib.classes.ConjunctionModule(name: str, outputs: list[str])[source]
Bases:
BaseModule
Keeps track of all inputs.
Changes internal state, then sends high/low based on internal state
- handle_pulse(input: str, pulse: Pulse) list[PulseTarget] [source]
Store pulse, then send based on current state.
If all our values are high, we send low to all our outputs. Otherwise, we send
LOW
to all our outputs.
- class day20.lib.classes.FlipFlopModule(name: str, outputs: list[str], state: Pulse = Pulse.LOW)[source]
Bases:
BaseModule
If we receive HIGH, we are a sink (do nothing).
If we receive LOW, flip our current value and send it to everyone
- handle_pulse(input: str, pulse: Pulse) list[PulseTarget] [source]
Handle pulse by forwarding if we receive low.
- class day20.lib.classes.LoopCounter(target_loop_count: int)[source]
Bases:
object
Keeps track of loop lengths.
- add_result(loop_name: str, value: int) None [source]
Adds a result to our loop_count.
If we already had a loop with that name, we ignore it.
- property finished: bool
Returns True if our loop_lengths are equal to our target.
- loop_lengths: dict[str, int]
- property num_results: int
Returns number of loop_lenghts submitted.
- target_loop_count: int
- class day20.lib.classes.MappingModule(name: str, outputs: list[str])[source]
Bases:
object
map to a list of outputs.
- name: str
- outputs: list[str]
- class day20.lib.classes.ModuleGroups(head: BroadcastModule, loops: list[list[BaseModule]], loop_tails: list[ConjunctionModule], penultimate: ConjunctionModule, sink: SinkModule)[source]
Bases:
object
A group of modules for part2.
- all_nodes: list[BaseModule]
- head: BroadcastModule
- loop_tails: list[ConjunctionModule]
- loops: list[list[BaseModule]]
- penultimate: ConjunctionModule
- sink: SinkModule
- class day20.lib.classes.Pulse(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Flag
Simple True/False enum.
- HIGH = True
- LOW = False
- class day20.lib.classes.PulseTarget(pulse: Pulse, src: str, target: str)[source]
Bases:
object
A pulse(low/high) from src to dest.
- src: str
- target: str
- class day20.lib.classes.SinkModule(name: str, outputs: list[str])[source]
Bases:
BaseModule
Sink module, gets something but sends it no where else.
- handle_pulse(input: str, pulse: Pulse) list[PulseTarget] [source]
Always eats inputs and never sends onwards.
day20.lib.parsers module
Day20 parsers.
- day20.lib.parsers.finalize_modules(modules: list[BaseModule]) list[BaseModule] [source]
Finalize construction of all modules.
For each module, calculate its inputs. Then inject the inputs into our conjunction modules Modifies modules inplace, and returns it
- day20.lib.parsers.get_modules(filename: str) list[BaseModule] [source]
Opens a file and returns all the modules.
- Parameters:
filename (str) – name of file to open
- Returns:
list of modules.
- Return type:
list[BaseModule]
- day20.lib.parsers.parse_line(line: str) BaseModule [source]
Parses a line into a BaseModule.
e.g.
%a -> inv, con
.
Module contents
Library modules for day20.