[REBOL] Re: A Rebol Challenge. The Monty Hall Puzzle
From: carl:cybercraft at: 17-Dec-2001 0:15
On 16-Dec-01, Reichart wrote:
> We Reboler have been challenged.
> I was posing some puzzles with some friends on another mailing list
> I belong to, the enjoyment of which is provided here first should
> you want to try and solve this for yourself. However, one of the
> people responding was a programmer, and he wrote a program to try to
> solve the problem. First he wrote this in Pearl (183 characters),
> then in Matlab (136 characters). I put it to you--smarter people
> than I--to put this man to shame! Give me your best Rebolette, and I
> will make him see the error of his ways :-)
> OK, no looking this up on the web. This is a real fun one if you
> have not seen it before, or better stated, worked through it.
> The scenario is such: you are given the opportunity to select one
> closed door of three, behind one of which there is a prize. The
> other two doors hide "goats" (or some other such "non-prize"), or
> nothing at all. Once you have made your selection, Monty Hall will
> open one of the remaining doors, revealing that it does not contain
> the prize. He then asks you if you would like to switch your
> selection to the other unopened door, or stay with your original
> choice. Here is the problem:
> Does it matter if you switch?
> P.S. this problem was presented to two of my engineers and myself
> many many years ago. We were told that the "staff" scientist at the
> company of the presenter all got it wrong. So the three of us worked
> on it together for about 25 minutes. Came to our conclusion, then
> wrote a computer program to "prove it." I then wrote a layman's
> description of "why." Which I found was needed because SO MANY
> PEOPLE CAN NOT ACCEPT THE ANSWER. Especially statisticians! Too
> funny. If anyone wants a copy, I will dig it up.
> Now for the Email from my friend:
> He writes...
> Nah, matlab is the way to go for this:
> b=sum(floor(3*rand(100,100))==0);y=floor(3*rand(100,100));
> o=(floor(2*rand(100,100))+1).*(y==0)+(3-y).*(y>0);c=sum(y.*o>0);
> d=sum(c>b-c<b); [b;c]
> if (d>90) fprintf(1,"Switching is better (95%%+ confidence)\n"); end
> But maybe you can do better in Rebol. I don't see a way to off the
> top of my head. Note that if we're just comparing the core
> computation, the matlab is barely three lines. (The "o" variable is
> not strictly needed, but I am including it anyway to explicitly
> construct the door-picked-by-Monty.)
> Perl is 183 characters, not counting invocation from the command
> line or comments. Matlab is 136.
> /usr/bin/perl -e 'print "St Sw (%win)\n";$d=0;for($i=0;$i<100;$i++){
> $b=0;$c=0;for($a=0;$a<100;$a++){$b+=int(rand(3))==0};
> for($a=0;$a<100;$a++){$y=int(rand(3));$o=$y?(3-$y):(int(rand(2))+1);
> $c+=$o*$y>0;};$d+=($c>=$b)-($c<=$b);print "$b $c\n"};print "St Sw
> (%win)"; if ($d>90) { print "\nSwitching is better (95%+
> confidence)" };print "\n"'
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.
--
Carl Read