Expand description
§Linen Layout
Solves both parts simultaneously. Part one is the number of designs with non-zero possible combinations.
An elegant approach to check if the design starts with any towel is to first build a
trie. Each node in the trie stores a bool
indicating
if it’s a valid towel and links to the next node for each possible color.
There are only 5 colors. A custom perfect hash
function maps indices between 0 and 7 so that they fit into a fixed size array. This is faster
than using a HashSet
.
Additionally we store the Trie in a flat vec
. This is simpler and faster than creating
objects on the heap using Box
.
Structs§
- Node 🔒Simple Node object that uses indices to link to other nodes.
Functions§
- Hashes the five possible color values white (w), blue (u), black (b), red (r), or green (g) to 0, 2, 4, 5 and 1 respectively. This compresses the range to fit into an array of 6 elements.
Type Aliases§
- Input 🔒