We all knew the writing staff of Futurama was brainy, but this is something else. In the episode “The Prisoner of Benda,” the Professor and Amy use a new invention to switch bodies. Unfortunately, they discover that the same two brains can’t switch twice and have to come up with some equation to prove that, with enough people switching, eventually everyone will end up in their rightful form. To work out the ridiculous brain switching plot line, writer Ken Keeler (who also just happens to have a PhD in mathematics) ended up writing and proving an entirely new theorem"
Link to Original Source