How to resolve the algorithm Perfect shuffle step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Perfect shuffle step by step in the Quackery programming language

Table of Contents

Problem Statement

A perfect shuffle (or faro/weave shuffle) means splitting a deck of cards into equal halves, and perfectly interleaving them - so that you end up with the first card from the left half, followed by the first card from the right half, and so on:

When you repeatedly perform perfect shuffles on an even-sized deck of unique cards, it will at some point arrive back at its original order. How many shuffles this takes, depends solely on the number of cards in the deck - for example for a deck of eight cards it takes three shuffles:

The TaskTest Cases

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Perfect shuffle step by step in the Quackery programming language

Source code in the quackery programming language

  [ [] swap 
    times [ i^ join ] ]       is deck     ( n --> [ )

  [ dup size 2 / split swap
    witheach 
      [ swap i^ 2 * stuff ] ] is weave    ( [ --> [ )

  [ 0 swap 
    deck dup 
    [ rot 1+ unrot
      weave 2dup = until ]
    2drop ]                   is shuffles ( n --> n )

' [ 8 24 52 100 1020 1024 10000 ] 

witheach 
  [ say "A deck of "
    dup echo say " cards needs " 
    shuffles echo say " shuffles." 
    cr ]

  

You may also check:How to resolve the algorithm Sorting algorithms/Merge sort step by step in the ATS programming language
You may also check:How to resolve the algorithm Averages/Simple moving average step by step in the Elena programming language
You may also check:How to resolve the algorithm Deal cards for FreeCell step by step in the Elixir programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the OCaml programming language
You may also check:How to resolve the algorithm 100 doors step by step in the K programming language