python solution (plus alt) for problem 17