Solution by Sean Meininger
