Mike Simmons wrote:I think that's equivalent to
(Correcting an off-by-one error.)
Junilu Lacar wrote:solution we've come up with
pick | (pick + 1) % 3 | (pick + 2) % 3 |
---|---|---|
0 | 1 | 2 |
1 | 2 | 0 |
2 | 0 | 1 |
Junilu Lacar wrote:So here's the simplest/clearest solution we've come up with
https://coderanch.com/t/40/754647/Simple-challenge-Monty-Hall#3502756
Liutauras Vilda wrote:
Junilu Lacar wrote:So here's the simplest/clearest solution we've come up with
https://coderanch.com/t/40/754647/Simple-challenge-Monty-Hall#3502756
To be brutally honest, to me it isn't a most simplest or clearest solution. You have to be quite intelligent to find it simplest or clearest.
Campbell Ritchie wrote:It would need comments to explain it
Stephan van Hulst wrote:The problem is that over time, comments have the habit of going out of sync with the code. Using explaining variables will not.
Agree. You can have a few other comments warranted by the circumstances, too.You can change the first example to use only one comment. The second example works a lot better if you actually have three things already countedJunilu Lacar wrote:. . . the kind of comment Stephan mentioned . . . is warranted.
Stephan van Hulst wrote:The alternative is no chance of divergence.
Campbell Ritchie wrote:And of course nobody should forget their /** Documentation Comments */
Mike Simmons wrote:
Well, I'm still of the opinion that in order to convince skeptics of the validity of the results, the simulation needs to actually simulate all the parts of the problem, not just simplify the unimportant parts out of existence. Otherwise we can reduce it to a random number simulator for already-known probabilities:
Junilu Lacar wrote:(Re the forum rendering bug: a ">" in a code block will throw its parsing logic for a loop. You can turn off HTML to skirt around the bug)
Junilu Lacar wrote:But isn't that line saying something very different from this one?
Junilu Lacar wrote:In your incantation, there's only one random pick and it's always compared to either 1 or 2, which already predetermines the outcome.
Mike Simmons wrote:
Well, I'd make that
![]()
There are three kinds of actuaries: those who can count, and those who can't.
Mike Simmons wrote:if you're working with someone who has agreed that your pickedTheCar() implementation will completely correlate with winning (if you don't switch) or losing (if you do switch)... then I don't know why they need the simulation at all.
To be clear, I completely agree with your logic.
Piet Souris wrote:Without loss of generality, you may assume that the contestant always chooses the first door. Simplifies things. Coming up with beautifully refactored code for such a trivial problem is easy enough. But what if the contestant has no clue whether to switch or not, and decides to flip a coin? Would that not be a muchmore interesting simulation? And those of us saying it is fifty-fifty wouldn't be far off...
Piet Souris wrote:Would that not be a muchmore interesting simulation? And those of us saying it is fifty-fifty wouldn't be far off...
Junilu Lacar wrote:
You're right, the empirical evidence does hover around 50% even when the contestant's pick is still random. This is how I interpreted your scenario.
Junilu Lacar wrote:How you phrased it isn't the logic expressed in the code though, if I understand what you're saying correctly.
Junilu Lacar wrote:The conditional statement "if by chance you happened to pick the car" is still random.
Junilu Lacar wrote:I need to look at my implementation that gives a 50-50 chance of winning if you randomly decide to switch or stay and why that was producing different results.
There are three kinds of actuaries: those who can count, and those who can't.
Junilu Lacar wrote:
I think the code is right. Anybody see why it would be wrong?
There are three kinds of actuaries: those who can count, and those who can't.
That feels good. Thanks. Here's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|