Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "monty hall problem"
-
A few weeks ago, I was kept up until the wee hours of the morning trying to figure out how in the hell the Monty Hall problem works. After finally getting it (I'm slow, okay?), I decided to write a program to run simulations of it.
First incarnation of program took user input. User enters what door they choose (1, 2, or 3), then is told what door Monty opens, then given the decision of staying with the door they originally chose or switching, then informed how that worked out for them.
Second incarnation of program ran on a loop. At the start of each loop, a random door is picked for the user guess. Then the door Monty opens is calculated from the remaining doors (excludes user guess and prize door). Then user switches doors (choosing the door that was not their original door or the door Monty opened). At the end of each loop, if the door they switched to was the prize door, it would increment a win counter, else increment a loss counter. After running the loop 1000000000 times, it printed to console `You always switched doors, resulting in ${wins} wins and ${losses} losses`.
THEN I decided to write a variation to run a while loop on the outside of the loop to increase the number of total doors until the point where the decision to switch doors hurt more often than it helped. At this point, I decided to incorporate file I/O and write to a file rather than a console. And that was neat!
And then I decided it would be cool to go back to the three door variation, printing on each loop the original door, the door Monty opened, the door that was switched too, the result of the switch (win or lose) and what the prize door was.
But for the life of me, I couldn't seem to get the file to write properly. It would, like, always crash my terminal. I tried open + append, I tried append. I tried createWriteStream. Still just failure.
And then I changed it to an appendFileSync and happened to look at one of the files that I was writing to. "Huh, over a gig seems a lot."
"Well, how much are you writing each loop? Did you forget to keep in mind how many bytes that would be?"
TLDR: If you're going to write a program that's going to write data to a file on a loop, you might want to figure out how much it's going to end up writing .... before trying to run it. And running a loop 1000000000 times may be a little excessive.
*face palm*2 -
I watched an episode of Brooklyn 99. Cop comedy show for those of you who don't know. They introduced me to the monty hall problem? My brain refuses to understand it and im rapidly losing my mind.
Has anyone here ever written a program that tests it? I can't read math theorems for shit. But I can read code. And I need my sanity back.2 -
so i recently found out about a problem called the "Monty Hall Problem" and decided to give it a go, so i wrote this little analysis app to solve it
https://github.com/bigworld12/...5 -
I solved the Monty Hall problem for once and for all! Suckers. Of course a computer can't decide if switching or keeping is the best choice. Even wikipedia states that switching wins. NEVER. And even if that would be the case, it's pure how you arranged the labels to determine which one wins. If everyone actually wrote their own code, the conclusion wouldn't be what it is now. Many people probably just changed their code until that false result comes out or had it at the beginning caused by lack of experience.
Here is a GOOD implementation: https://pastebin.com/dRiTWQpw
It gives a 50%-ish chance on a choice like mathematically is correct.
The problem is in the computer simulations: using > or < to check which choice has won. But actually, often no one has won (it's a tie) after running it x times so you have to filter out the ==.
Then, you get the right results. My first version also had a bias, but i refused to accept it and did spent 45 minutes on the code instead of 15. This is the end result. And no, with double ?: in a printf statement i don't expect a prize.
It was a lot of fun actually, did not expect this from such stupid 'problem'35