Solves both parts at once, relying on the regular nature of the input. Each number is always a single digit.