stubbed out problem 7
translated a ruby solution that seems to be correct