Finished the first version of the problem 12 solution. It got the correct answer, but took around 15 minutes to solve.