pub fn y15d19p1(input: &str) -> u32
Expand description
The solution for part one of the day nineteen challenge.
As usual we take the problem input as a string and then start parsing it.
The input contains all of the replacements followed by an empty line and
then the molecule. So we parse the replacements until we get to the empty
line and then the molecule is the final line. Once we have our replacements
we loop through them and then we loop and for each of them we loop through
the windows of the molecule of the size of the replacement so that we can
see if we can do a replacement. If we can then we build a new molecule
using the replacement and then add it to our tracking
std::collections::HashSet
(we’re only supposed to find distinct
molecules). Once we’ve checked all of the possibilities for all of the
replacements we just return the length of our set.
§Example
// probably read this from the input file...
let input = "Al => ThF\nAl => ThRnFAr\nB => BCa\nB => TiB\n\nnPBP";
assert_eq!(y15d19p1(input), 2);