Best shuffle: Difference between revisions

Content added Content deleted
(Updated first D entry)
Line 2,352: Line 2,352:
===Swap if it is locally better algorithm===
===Swap if it is locally better algorithm===
With added randomization of swaps!
With added randomization of swaps!
<lang python>from collections import Counter
<lang python>import random
import random


def count(w1,wnew):
def count(w1,wnew):
Line 2,369: Line 2,368:
if i != j and wnew[j] != wnew[i] and w[i] != wnew[j] and w[j] != wnew[i]:
if i != j and wnew[j] != wnew[i] and w[i] != wnew[j] and w[j] != wnew[i]:
wnew[j], wnew[i] = wnew[i], wnew[j]
wnew[j], wnew[i] = wnew[i], wnew[j]
break
wnew = ''.join(wnew)
wnew = ''.join(wnew)
return wnew, count(w, wnew)
return wnew, count(w, wnew)