Open mtwelker opened 2 years ago
It was detailed in the solutions distributed for lab 1.
It come about when we are trying to open a goat door after the first selection was made. There are two scenarios - the contestant selects a goat door or car door.
When they select a goat door there is only one other door that can be opened.
When they select the car door then we have to randomly pick one of the two goat doors.
Many people implemented one general solution for both cases.
The problem arises when only have one door to select, but we use the sample() function. When a single value is used as the object to sample from it generates the sequence ending in that value.
When 2 is the only possible door to open the correct door returned from the function should be 2, but the function will return 1 or 2 if we use sample.
Similarly with three except it will return 1, 2 or 3.
The error is that the function will open the wrong door. It will happen in 18% of the games, leading to improper estimates of the likely success of both strategies.
does that make sense?
Yes, that is very helpful. I thought I had read about this bug before but couldn't find the details. I'll go back and read the solutions again. Thank you!
I have read Unit Testing section in this week's practice problems over and over and still don't understand what the bug is that we're supposed to be testing. At the very beginning, it says:
What is the bug here? Is it that
sample( x=3, size=1, replace=FALSE )
produced different results thansample( x=1:3, size=1, replace=FALSE )
? Because when I run them, they both seem to return a single number randomly sampled from 1, 2, and 3. I don't understand what the bug is that we're investigating.As the problem continues, it says :
Again, I'm not sure what this means. When you say it will result in the "wrong" door opened, do you mean a goat door instead of a car door? Or do you mean a different door than the coder intended?
If this was explained in more detail elsewhere, please let me know where. I've looked through previous notes but can't find anything about this bug. Thanks for any explanation you can offer!