22 lines
688 B
Text
22 lines
688 B
Text
procedure main(a)
|
|
n := integer(!a) | 20
|
|
every (nr|nw|nb) := ?n-1
|
|
sIn := repl("r",nw)||repl("w",nb)||repl("b",nr)
|
|
write(sRand := bestShuffle(sIn))
|
|
write(sOut := map(csort(map(sRand,"rwb","123")),"123","rwb"))
|
|
if sIn ~== sOut then write("Eh? Not in correct order!")
|
|
end
|
|
|
|
procedure bestShuffle(s) # (Taken from the Best Shuffle task)
|
|
t := s
|
|
every !t :=: ?t # Uncommented 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 csort(w)
|
|
every (s := "") ||:= (find(c := !cset(w),w),c)
|
|
return s
|
|
end
|