Day 14: Docking Data¶
Classes:
|
Represent the bitmask of the initialization program. |
|
Represent a write to the memory. |
|
Represent the initialization program. |
|
Represent the state of the memory. |
Functions:
|
Parse the text as an clearing and a setting mask, respectively. |
|
Parse the write instruction and return (address, value). |
|
Parse the input into an initialization program. |
|
Execute the program and return the memory values. |
|
Sum the values in the memory slots. |
- class Mask(clearing: int, setting: int)[source]¶
Represent the bitmask of the initialization program.
Methods:
__init__
(clearing, setting)Initialize with the given values.
Attributes:
mask of the bits to be cleared (
AND
'ed)mask of the bits to be set (
OR
'ed)- __init__(clearing: int, setting: int) None [source]¶
Initialize with the given values.
- Requires
0 <= setting <= 2**36 - 1
0 <= clearing <= 2**36 - 1
- clearing: Final[int]¶
mask of the bits to be cleared (
AND
’ed)
- setting: Final[int]¶
mask of the bits to be set (
OR
’ed)
- parse_mask(text: str) Mask [source]¶
Parse the text as an clearing and a setting mask, respectively.
- Requires
MASK_RE.match(text)
- Ensures
0 <= result.setting <= 2**36 - 1
(The setting mask not too large)
0 <= result.clearing <= 2**36 - 1
(The clearing mask not too large)
- class Write(address: int, value: int)[source]¶
Represent a write to the memory.
Methods:
__init__
(address, value)Initialize with the given values.
Attributes:
Address (offset) in the memory
Value to be written
- __init__(address: int, value: int) None [source]¶
Initialize with the given values.
- Requires
0 <= value <= 2**36 - 1
(The value in expected range)
address >= 0
- address: Final[int]¶
Address (offset) in the memory
- value: Final[int]¶
Value to be written
- parse_write(text: str) Tuple[int, int] [source]¶
Parse the write instruction and return (address, value).
- Requires
WRITE_RE.match(text)
- Ensures
result[1] >= 0
(Value non-negative)
result[0] >= 0
(Address non-negative)
- class Program(mask: Mask, writes: List[Write])[source]¶
Represent the initialization program.
Methods:
__init__
(mask, writes)Initialize with the given values.
Attributes:
Mask used throughout the program
Write instructions
- parse_lines(lines: Lines) Program [source]¶
Parse the input into an initialization program.
- Requires
len(lines) > 2
MASK_RE.match(lines[0])
all(WRITE_RE.match(line) for line in lines[1:])
- class Memory(slots: Mapping[int, int])[source]¶
Represent the state of the memory.
Methods:
__init__
(slots)Initialize with the given values.
Attributes:
Slot map as address 🠒 value
- __init__(slots: Mapping[int, int]) None [source]¶
Initialize with the given values.
- Requires
all(key >= 0 for key in slots.keys())
(Addresses non-negative)
all(value >= 0 for value in slots.values())
(Values non-negative)
- slots: Final[Mapping[int, int]]¶
Slot map as address 🠒 value