Both part one and part two rely on the fold method. This method comes in useful for a lot of Advent of Code problems so is handy to know about. The input is parsed into a tuple enum Sub for convenience.
fold
Sub