  An algorithm based on backward induction is devised in order to compute the
optimal sequence of games to be played in Parrondo games. The algorithm can be
used to find the optimal sequence for any finite number of turns or in the
steady state, showing that ABABB... is the sequence with the highest steady
state average gain. The algorithm can also be generalised to find the optimal
adaptive strategy in a multi-player version of the games, where a finite number
of players may choose, at every turn, the game the whole ensemble should play.
