pub fn parse(input: &str) -> Input
Expand description
Parse the input into an adjency matrix of edges compressed into u32
bitfields.
First, each cave is assigned a unique index, with 0
reserved for the start
cave and 1
reserved for the end
cave. For example the sample input caves are:
start | end | A | b | c | d |
---|---|---|---|---|---|
0 | 1 | 2 | 3 | 4 | 5 |
Next a vec
of u32
with an entry for each cave at the corresponding index is created with
a bit set for each other cave reachable at 2^n
where n is the cave index. The start cave
can only be visited once at the beginning, so it is removed from all edges.
For example the sample start cave vec
looks like:
cave | index | edges |
---|---|---|
start | 0 | 1100 |
end | 1 | 1100 |
A | 2 | 11010 |
b | 3 | 100110 |
c | 4 | 100 |
d | 5 | 1000 |
Finally all small caves are added to a single u32
, for example the
sample data looks like 111011
.