RosettaCodeData/Task/Topswops/00DESCRIPTION

38 lines
1.5 KiB
Plaintext

Topswops is a card game created by John Conway in the 1970's.
Assume you have a particular permutation of a set of   n   cards numbered   1..n   on both of their faces, for example the arrangement of four cards given by   [2, 4, 1, 3]   where the leftmost card is on top.
A round is composed of reversing the first   m   cards where   m   is the value of the topmost card.
Rounds are repeated until the topmost card is the number   1   and the number of swaps is recorded.
For our example the swaps produce:
<pre>
[2, 4, 1, 3] # Initial shuffle
[4, 2, 1, 3]
[3, 1, 2, 4]
[2, 1, 3, 4]
[1, 2, 3, 4]
</pre>
For a total of four swaps from the initial ordering to produce the terminating case where &nbsp; 1 &nbsp; is on top.
For a particular number &nbsp; <code> n </code> &nbsp; of cards, &nbsp; <code> topswops(n) </code> &nbsp; is the maximum swaps needed for any starting permutation of the &nbsp; <code>n</code> &nbsp; cards.
;Task:
The task is to generate and show here a table of &nbsp; <code> n </code> &nbsp; vs &nbsp; <code> topswops(n) </code> &nbsp; for &nbsp; <code> n </code> &nbsp; in the range &nbsp; 1..10 &nbsp; inclusive.
;Note:
[[oeis:A000375|Topswops]] is also known as &nbsp; [http://www.haskell.org/haskellwiki/Shootout/Fannkuch Fannkuch] &nbsp; from the German Pfannkuchen meaning &nbsp; [http://youtu.be/3biN6nQYqZY pancake].
;Related tasks:
* [[Number reversal game]]
* [[Sorting algorithms/Pancake sort]]
<br><br>