This looks obvious to me:
simulateMontyHall=: 3 : 0
nt=. y. NB. Number of trials
initialPick=. ?nt$3 [ carDoor=. ?nt$3 NB. Independent probabilities
openChoices=. initialPick-.~&.>carDoor-.~&.>nt$<i.3
hostOpen=. openChoices{~&>?#&>openChoices NB. Host limited in door to
open.
stay=. carDoor=initialPick
switch=. carDoor=,initialPick-.~&>hostOpen-.~&.>nt$<i.3
+/&>stay;switch
)
simulateMontyHall 1e5
33188 66812
6!:2 'simulateMontyHall 1e5'
0.60886845
6!:2 'simulateMontyHall 1e6'
6.8520505
simulateMontyHall 1e6
331938 668062
On 9/7/06, Oleg Kobchenko <[EMAIL PROTECTED]> wrote:
After a longer pause... "Of course, it's obvious!"
--- Roger Hui <[EMAIL PROTECTED]> wrote:
> Ahem. It just has to be clear and convincing to me.
...
--
Devon McCormick
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm