previous | index | next

Shuffle Problem Approach

  1. Let a deck be represented by (1 2 3 ... 52).

  2. Use integers-from-to to create the deck.

  3. Use first-elements-of and list-tail to create the halves (1 2 3 ... 26) and (27 28 29 ... 52).

  4. Use a procedure interleave to interleave the two halves:
         (interleave (1 2 3 ... 26)
                     (27 28 29 ... 52)) ⇒ (1 27 2 28 3 29 ... 26 52)
    
  5. Check if the result is (1 2 3 ... 52).

  6. If not, repeat step 3 on the result.

previous | index | next