My solution to #61.
I'm not sure how easy the code is to follow!