Function aoc::year2021::day12::parse

source ยท
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:

startendAbcd
012345

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:

caveindexedges
start01100
end11100
A211010
b3100110
c4100
d51000

Finally all small caves are added to a single u32, for example the sample data looks like 111011.