Question 4.
Quick draft of brute-force python solution for testing+figuring out algorithm
Wrote the solution in C++. TODO: generalize.
improved python solution
c++ solution with 9999. Runtime test says 0.2 seconds, against 6.8 for similar (but way shorter) python implementation.