The described trick is a "ducky" version of the trick known as Hummer's 3-Object Divination, which is described in Martin Gardner's book "Mathematics, Magic and Mistery" (Dover Publ., New York, 1956).
There are three different rubber ducks on the table:
The mathemagician and the participator agree on naming the positions, e.g. the position of the yellow duck above they name position 1, the middle position they name 2 and the third one they name 3. After that the participator is to select one duck, but not name it. Then the mathemagician turns his back to the table and gives the following instruction: "First switch the two ducks you haven't chosen and do not tell me the positions involved. After that you can switch any two ducks as many times as you want, but for all these other switches you tell me the positions involved." After that the mathemagician turns around and can instanteneously tell which duck the participator has chosen in the beginning.
Say the participator selected the yellow duck. Then in the first switch he would change the positions of the pink and blue duck:
After that he continues switching, but with naming the positions: say he switches now the pink and yellow duck:
In this case he says that he has switched positions 1 and 2.
Then he decides to switch the pink and yellow duck again, saying the switch involved positions 1 and 2:
When switching the pink and blue duck he says that he switches 2 and 3:
Say that the participator decides to stop here. The mathematician turns around and says: "You chose the yellow duck!"
The principle of this trick is simple logic. All the mathemagician has to do is to choose a duck himself in the beginning. When the participator starts announcing the position changes it is not hard to follow the path of his duck. Say, the mathemagician chose the blue duck in the beginning and remembers its position (2). When participator says that he has changed 1 and 2, the mathemagician supposes the blue duck is now at position 1. In the next switch above the same positions are involved, so the blue duck should be back to 2. I the final switch 2 and 3 are involved so in the end the blue duck should be at position 3.
Now the blue duck is either the one chosen by the spectator or not. If not (as in the case describe above) it was involved in the first switch that happened without naming the positions, so it cannot be on position 3. On the other hand, if the participator had also chosen the blue duck, then it wouldn't be involved in the first switch and thus must be on position 3.
So all the mathemagician has to do when he turns around is: check if "his" duck (blue) is at the expected position (3). If yes, then it is the duck chosen by the participator, otherwise the participator has chosen the duck that is neither blue neither at position 3 (in the example above the pink duck is at position 3, so the participator has chosen the third, i.e. yellow, duck). That's all, folks!