Solution by Daniel Bowling