Problem 6 solved with Python.