In an episode of the cartoon, a machine lets characters swap bodies, but they can’t switch back with the same person. Math helps all the characters return to their original bodies