Algorithms

Reverse algorithms laboratory

Choose the result and reconstruct the starting state: a deck of cards or a Josephus circle. Watch, pause and undo every move.

Read the explanation and the two problems

The deck of cards

Forward: take from the bottom, place on top; take from the bottom, place on the table. Backward: take back from the table, place underneath; take from the top, place underneath.

From 1 to 30 cards. The desired order is chronological: the first removal is on the left.

Deck in hand

Top
    Bottom

    Card in transit

    Pile on the table

    Top
      Bottom

      Desired removals, first to last

      Observed removals, first to last

      Compare simulation and permutation

      Position labels are counted from the bottom: simulate the game, then assign each position the value required when it is removed.

      Removed position (from bottom)Value to assign