Added solution for problem 12. I should probably make it faster.