Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Best-shuffle/Zkl/best-shuffle-1.zkl
Normal file
15
Task/Best-shuffle/Zkl/best-shuffle-1.zkl
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
fcn bestShuffle(str){
|
||||
s:=str.split("").shuffle(); // -->List
|
||||
if(not s) return(str,str.len()); // can't shuffle "" or "a"
|
||||
|
||||
n:=str.len();
|
||||
foreach i in (n){
|
||||
foreach j in (n){
|
||||
if (i!=j and s[i]!=str[j] and s[j]!=str[i]){
|
||||
s.swap(i,j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(s.concat(), s.zipWith('==,str).sum(0));
|
||||
}
|
||||
5
Task/Best-shuffle/Zkl/best-shuffle-2.zkl
Normal file
5
Task/Best-shuffle/Zkl/best-shuffle-2.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
ss:=T("abracadabra","immediately","grrrrrr","seesaw","pop","up","a","");
|
||||
foreach s in (ss){
|
||||
ns,cnt:=bestShuffle(s);
|
||||
println("%s --> %s (%d)".fmt(s,ns,cnt));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue