Solution to problem 5.

that was a pain in the ass.