Solution by Alex Daniel.
