Worked on #31

This is an interesting situation, because I found a solution based on
the concept of the problem, but I don't grasp WHY the solution actually
works. Tomorrow - the knapsack problem!