RosettaCodeData/Task/Best-shuffle/Mathematica/best-shuffle.math

6 lines
290 B
Text
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
BestShuffle[data_] :=
Flatten[{data,First[SortBy[
List[#, StringLength[data]-HammingDistance[#,data]] & /@ StringJoin /@ Permutations[StringSplit[data, ""]], Last]]}]
Print[#[[1]], "," #[[2]], ",(", #[[3]], ")"] & /@ BestShuffle /@ {"abracadabra","seesaw","elk","grrrrrr","up","a"}