The Prisoner of Benda

"The Prisoner of Benda" is the ninety-eighth episode of Futurama, the tenth of the sixth production season and the seventh broadcast season.

The story
A revolutionary invention allows the crew members to exchange minds, but it goes haywire and it's up to Farnsworth and the Harlem Globetrotters to fix it. According to David X. Cohen, writer Ken Keeler penned a theorem (and proof thereof) based on group theory, then used it to explain a plot twist in this episode.