On Fri, Apr 18, 2008 at 11:06 PM, Mark J. Reed <[log in to unmask]> wrote:
> The "swap with any item at any time" version gives one card an equal
> opportunity to land at any position *at each step* of the algorithm,
> but over the course of the whole trip you give out too many
> opportunities and wind up with an uneven balance at the end. This is,
> again, easy to see if you use a small list and enumerate the results.
> For example, with a three-item list, only the original first element
> is equally likely to wind up anywhere. The second element is most
> likely to wind up first (37% chance), slightly less likely to wind up
> third (33%), and even less likely to wind up still in second position
> (30%). The third element is most likely to wind up second, then
> third, then first, with the same percentages.
This script will demonstrate those numbers:
-- record how many times each item winds up in each position
set total to 0
set pos to {{0,0,0},{0,0,0},{0,0,0}}
-- ^-- number of times item 1 winds up in position 1
-- ^-- number of times item 1 winds up in position 2
-- ^-- number of times item 2 winds up in position 1
-- etc.
repeat with i from 1 to 3
repeat with j from 1 to 3
repeat with k from 1 to 3
tell {1, 2, 3}
set {item 1, item i} to {item i, item 1}
set {item 2, item j} to {item j, item 2}
set {item 3, item k} to {item k, item 3}
repeat with p from 1 to 3
tell item (item p) of pos to set its item p to (its item p) + 1
end repeat
end tell
set total to total + 1
end repeat
end repeat
end repeat
set resultStr to "Out of " & total & " shuffles:" & linefeed & linefeed
repeat with startPos from 1 to 3
repeat with endPos from 1 to 3
set counted to item endPos of item startPos of pos
set percent to ((floor(1000*counted/total))/10.0 as string)
set resultStr to resultStr & tab & "There were "
if counted < 10 then
set resultStr to resultStr & " "
end if
set resultStr to resultStr & counted & " times where item " & ¬
startPos & " wound up in position " & endPos & ¬
" (" & percent & "%)" & linefeed
end repeat
set resultStr to resultStr & linefeed
end repeat
resultStr
It gives this output:
Out of 27 shuffles:
There were 9 times where item 1 wound up in position 1 (33.3%)
There were 9 times where item 1 wound up in position 2 (33.3%)
There were 9 times where item 1 wound up in position 3 (33.3%)
There were 10 times where item 2 wound up in position 1 (37.0%)
There were 8 times where item 2 wound up in position 2 (29.6%)
There were 9 times where item 2 wound up in position 3 (33.3%)
There were 8 times where item 3 wound up in position 1 (29.6%)
There were 10 times where item 3 wound up in position 2 (37.0%)
There were 9 times where item 3 wound up in position 3 (33.3%)
--
Mark J. Reed <[log in to unmask]>
|