this is horrible, I'm not proud of it. There surely is some mathematical
feature that allows a smarter solution, but after I've not been able to
find that for a while, I've decided to just brute force it. Due to that,
I've not had any motivation to finish this solution on time or to remove
the loads of redundant code I've written here..