We actually studied this yesterday in my philosophy class (minus the loop the loop). It's a scenario to practically apply hedonistic calculus, which is a way of deciding what's morally right to do by calculating what will cause the most happiness (happiness being defined as pleasure and the absence of pain).
Actually quite a bit more complicated than that. You have to calculate the intensity, duration, certainty of outcomes, propinquity, purity, fecundity and extent of the pain experienced for all involved and then based on that, whatever scenario provides the lowest number causes the least amount of pain for all involved, and thus is the morally correct action to take.
.
.
d(happiness)/d(time)=?=d(sadness)