Problem 037 solution.
Problem 038 solution.
Problem 039 solution. Runs in 3m50s. Could be optimized, I'm sure.