11

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*

Comments
  • 5
    I was playing around with the tools that come with Kali and let one of the password generators go. I didn't realize the mistake I made whenever I let it go 6-8 chars with alphanumeric & special chars allowed.

    It was like a 3 gb file if I remember correctly.

    Oh and this was all done on a raspberry pi
  • 1
  • 2
    @Stuxnet I've committed the same crime lmao. Except I fucked up so bad that my machine wouldn't respond and I had to hard reset my machine and it wouldn't boot afterwards. Then I learned you don't have to pipe in all the possible permutations from a file and you can run them from memory which increases the hashing speed like 5x.
Add Comment