Solution by Dave Cross
