RosettaCodeData/Task/Topswops/Mathematica/topswops.math

9 lines
233 B
Text
Raw Permalink Normal View History

2013-04-11 01:07:29 -07:00
flip[a_] :=
Block[{a1 = First@a},
If[a1 == Length@a, Reverse[a],
Join[Reverse[a[[;; a1]]], a[[a1 + 1 ;;]]]]]
swaps[a_] := Length@FixedPointList[flip, a] - 2
Print[#, ": ", Max[swaps /@ Permutations[Range@#]]] & /@ Range[10];