based on problems from http://interactivepython.org/runestone/static/pythonds/index.html