Solving #8 by @freewil