The most unrealistic part of #adventofcode is that the samples provided always match what's in the real data.
This is not how programming works ;-)
However it can't be done differently for this kind of exercise. https://twitter.com/coderbyheart/status/1335565432842051585