Module day14

Source
Expand description

Β§Extended Polymerization

The key insight to this problem is the same as Day 6. We track the total number of each pair as the positions don’t affect the final result.

Fixed sized arrays are used for speed as we know that the elements are limited to 26 values and the possible pairs to 26 * 26 values.

StructsΒ§

Input
Rule

FunctionsΒ§

element πŸ”’
Convert a single uppercase ASCII character to an index between 0 and 25
pair πŸ”’
Convert two uppercase ASCII characters to an index between 0 and 675.
parse
Count the initial pairs and elements and parse each instruction into a Rule struct.
part1
Apply 10 steps.
part2
Apply 40 steps.
steps πŸ”’
Simulate an arbitrary number of steps.

Type AliasesΒ§

Elements πŸ”’
Pairs πŸ”’
Rules πŸ”’