Working out the jug problem in python