Pretty rough, this is my initial solve. Part 2 needs to be sped up, but is currently 3 seconds on my PC and my dataset.