Magic Tray Algorithm Input: Magic Tray in any initial configuration Output: All cups in the same orientation (1) If light is not red, enter side pockets and turn both cups up. If the light is red, terminate. (2) Enter diagonal pockets and turn both cups up. If the light is red, terminate. (3) The tray state is now: 1 1 1 0 Enter diagonal pockets and if you luckily found down cup, turn it up and terminate. Otherwise, turn any one cup down. Now the state is: 1 0 1 0 (4) Enter side pockets and turn both cups the other way. If the light is red, terminate. Otherwise,the state becomes: 0 1 1 0 (5) Enter diagonal pockets and turn both cups the other way and terminate.