Problem 1, written in Python