Struct advent_of_code_2021::day_23::Burrow [−][src]
Expand description
Represents a burrow as an integer that can be used as a list of 3-bit sections. 0-6 are the 7 cells in the hallway
where a Amphipod can stop, the cells adjacent to each side tunnel are not represented here, and instead handled by
build_states accounting for them when calculating costs. The remaining cells represent the side-tunnels, reading
like a book. You can walk down a tunnel by staring at indices 7, 8, 9 or 10, and increasing by 4 each step. It is
possible to represent a burrow of up to depth 8 in the u128 used.
The cells themselves use the numbers 0-4 to represent the types, 5 - 7 are unused:
- 0 - Empty
- 1 - Amber
- 2 - Bronze
- 3 - Copper
- 4 - Desert
Fields
len: usizeThe number of cells in the grid. 15 for depth 2 (part one) and 23 for depth 4 (part two)
positions: u128Each cell maps to 3 bits in this integer
Implementations
Return the number representing the state at a given cell offset.
update the positions integer with the value in pos.
Set cell offset 1 in a 4-cell burrow to 4, original value = 4321 (100 011 010 001):
let offset = 6; // i.e. the first bit after the 3 bits of the cell.'
let bits = (1 << self.len /*4*/ * 3) // 1 000 000 000 000
-1; // 111 111 111 111
let hole = 7u128 << offset; // 000 111 000 000
let mask = hole ^ bits; // 111 000 111 111
let zeroed = self.positions & mask; // 100 011 010 001
// & 111 000 111 111
// ---------------
// 100 000 010 001
self.positions = zeroed | (val << offset); // 100 000 010 001
// | 000 100 000 000
// ---------------
// 100 100 010 001
// = 4421Trait Implementations
Parses a string in the format .......BCBDDCBADBACADCA as a Burrow. Used mostly for testing. See `parse_input
for parsing the actual puzzle input
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Burrow
impl UnwindSafe for Burrow
Blanket Implementations
Mutably borrows from an owned value. Read more
