Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Best-shuffle/Icon/best-shuffle-1.icon
Normal file
1
Task/Best-shuffle/Icon/best-shuffle-1.icon
Normal file
|
|
@ -0,0 +1 @@
|
|||
# every !t :=: ?t # Uncomment to get a random best shuffling
|
||||
18
Task/Best-shuffle/Icon/best-shuffle-2.icon
Normal file
18
Task/Best-shuffle/Icon/best-shuffle-2.icon
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
procedure main(args)
|
||||
while scram := bestShuffle(line := read()) do
|
||||
write(line," -> ",scram," (",unchanged(line,scram),")")
|
||||
end
|
||||
|
||||
procedure bestShuffle(s)
|
||||
t := s
|
||||
# every !t :=: ?t # Uncomment to get a random best shuffling
|
||||
every i := 1 to *t do
|
||||
every j := (1 to i-1) | (i+1 to *t) do
|
||||
if (t[i] ~== s[j]) & (s[i] ~== t[j]) then break t[i] :=: t[j]
|
||||
return t
|
||||
end
|
||||
|
||||
procedure unchanged(s1,s2) # Number of unchanged elements
|
||||
every (count := 0) +:= (s1[i := 1 to *s1] == s2[i], 1)
|
||||
return count
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue