Solution by Steve Rogerson