Solution by John Barrett
