Possible (but slow) solution to problem 41.
Quick solution to problem 41.