Mailing List Archive: 49091 messages

## [REBOL] Re: A Rebol Challenge. The Monty Hall Puzzle

### From: carl:cybercraft at: 17-Dec-2001 21:13

```

> Not being a statistician, (or having a clue what the above code
> does:), my approach to such problems is to simulate them many times
> and see if there's a noticable difference in the results. So here's
> my code to do that, but it may be bugged as it wasn't giving the
> results I was expecting. But then, what's expected is not what we're
> supposed to get, right? (:

> rebol[]k: s: 0 r: func[n][random n]a: does[p: r 3 c: r 3 p = c]
> loop 10000 [if a[k: k + 1]if if not a[r 2 = 1][s: s + 1]]print
> ["Kept" k "Switched" s]

> I especially like the "if if" as it sounds like an accurate
> description of my code. (: Anyway, it's 151 bytes long for what it's
> worth.

I thought the above was bugged, and it was.  Here's a fixed version...

rebol[]k: s: 0 r: func[n][random n]m: does[p: r 3 c: r 3 p = c] loop
10000 [if m[k: k + 1]if not m[s: s + 1]]print ["Kept" k "Switched" s]

Nowhere near as short as some of the other posts, but anyway, here's
my reasoning behind it...

The prize is placed behind one of 3 doors...

prize: random 3

You choose one of the doors...

chosen: random 3

Now, Monty can see if they're a match - ie, if you've picked a
winner...

matched?: prize = chosen

Which returns true if you've chosen the prize.  If you decide to keep
this then it's obvious (I hope:) that you had 1 chance in 3 of
picking the prize.

But what if you accept Monty's offer to switch?  Well, there's only
two posibilities:

1) You'd chosen the prize, so switching from that means you lose
regardless of what Monty does.

2) You hadn't chosen the prize, Monty exposes the other losing door,
and so you switch to the winning door.

So a switch always means a reversal of your original choice - a
winning choice becoming a losing one and vice-versa.  So...

matched?: not matched?

But what happens to the "1 chance in 3 of picking the prize."?  Well
that also means you had 2 chances in 3 of losing, right?  And the
switch makes an original loss a win, so switching gives you 2 chances
in 3 of winning, thus doubling your chances of a win.

Note that I originally (though vaguely) thought switching would
improve your chances from 1 in 3 to 1 in 2, but this result is much
more fun. (:

--