Anonymous user
Best shuffle: Difference between revisions
→Swap if it is locally better algorithm
(Updated first D entry) |
|||
Line 2,352:
===Swap if it is locally better algorithm===
With added randomization of swaps!
<lang python>
def count(w1,wnew):
Line 2,369 ⟶ 2,368:
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]
break
wnew = ''.join(wnew)
return wnew, count(w, wnew)
|