Mathematics × Programming Competition #8 - Programmatic solution