Solution by James Smith
