Both part 1 and part 2 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