Using nim streams this was a breeze, and got solved a lot quicker than what I expected, quite a lot of fun :)