Lecture 17: LET'S GO GAMBLING (Monte Carlo Approximations)
Watch on YouTube →
Overview
Professor Rosen introduces Monte Carlo approximation by simulating a seven-card game with five black cards and two red cards, then estimates its win rate at about 28.6% from 100,000 trials, close to the exact probability. He also demonstrates why switching wins about two-thirds of the time in the Monty Hall problem, connects simulation to numerical analysis, and previews programming projects and a Hawaiian pronunciation assignment.
Key takeaways
- The five-black, two-red card game has a 28.57% win chance because drawing three black cards without replacement has probability (5/7) × (4/6) × (3/5).
- A Monte Carlo estimate becomes more stable as trials increase: Professor Rosen's card simulation moves from highly variable results at 10 trials to about 28.6% at 100,000 trials.
- In the Monty Hall problem, switching wins about two-thirds of the time because the host's informed goat reveal preserves the original 2/3 probability that the car was behind one of the unchosen doors.
- Python's random.shuffle randomizes a list in place, while random.sample selects a specified number of unique elements without replacement.
- A Hawaiian pronunciation program should test vowel pairs before single letters and can use dictionaries to map characters or pairs to phonetic sounds.
- Simpson's paradox warns that group-level comparisons, such as separate yearly batting averages, can reverse when the groups are combined.
Chapters
- Professor Rosen points students to an announcements list of past final projects that earned a 100 and exemption from the final exam.
- The gallery spans science projects, art, gadgets, tools, and games, including a turtle project, a guitar plugin, and a Bad Apple display demo.
- The Doom and Bad Apple examples illustrate the meme of adapting games or visual demos to unusual devices and displays.
- A student combined a Raspberry Pi, Ubuntu, Python, GPIO, and a magnetic switch to detect when a goat gate opened.
- The project sent an automatic email with a photo and the subject “Who let the goats out?” when the switch changed state.
- Building it required troubleshooting the switch and learning how pull-up and pull-down resistors affect input detection.
- Hand Jam, built in Unity, is a five-level mini-game with 2D objects arranged in 3D space, camera-based transitions, original music, and a boss fight.
- Professor Rosen praises the game's deliberately rough WarioWare-style aesthetic and recommends visual novels as another creative project format.
- Ren'Py supports visual novels with relatively little Python; examples include Doki Doki Literature Club and Slay the Princess.
- GB Studio and PICO-8 offer constrained retro-game workflows, while Unity, Unreal Engine, and Godot support broader game development.
- Ren'Py is presented as a Python-backed framework for branching visual novels and interactive stories.
- Slay the Princess demonstrates how hand-drawn art, voice acting, parallax effects, and player choices can create a polished narrative experience.
- Professor Rosen recommends these tools as project options because they let students focus on storytelling and design without extensive programming.
- The assignment converts valid Hawaiian words into pronunciation, using a 12-letter alphabet with five vowels and seven consonants.
- A dictionary maps individual letters and vowel pairs to sounds; the program must check pairs before single characters.
- The example keiki, meaning “child,” should retain the vowel-pair pronunciation rather than being reduced to an incorrect single-vowel sound.
- The planned program separates word validation from pronunciation and largely ignores accent marks.
- The game uses five black cards and two red cards: a player wins by drawing three cards without drawing red.
- The successive safe-draw probabilities are 5/7, 4/6, and 3/5, so the overall chance is their product, about 28.6%.
- Looking at each draw as individually more likely than not to be safe makes the game seem favorable, but multiplying the dependent probabilities reveals a poor bet.
- Monte Carlo approximation estimates outcomes by observing many simulated trials instead of deriving the answer directly.
- The name refers to Monte Carlo, Monaco, and its famous casino; the method applies the logic of tracking game outcomes to computational simulations.
- Professor Rosen contrasts simulation with formal probability calculations and notes that blackjack odds depend on play strategy and card counting.
- The card simulation imports Python's random module and represents the deck as two red-card values plus five black-card values.
- random.shuffle changes the list in place, producing a randomized order for each trial.
- The underlying random functions use pseudorandom values and can support operations such as choosing numbers, selecting elements, and shuffling sequences.
- A setup function creates and shuffles the deck, while a game function evaluates one round and returns True for a win or False for a loss.
- The player can examine the first three shuffled cards because any fixed three-card positions have the same distribution as any other three positions.
- The program counts wins across repeated calls rather than printing every individual outcome, avoiding unnecessary output during large runs.
- With only 10 trials, the estimated win rate swings widely; 10,000 trials produce results near 28%, and 100,000 trials produce about 28.6%.
- The exact calculation, (5/7) × (4/6) × (3/5), gives about 28.57%, validating the simulation.
- More trials generally stabilize the estimate but take longer to run, so the useful precision depends on the decision being made.
- Numerical analysis uses approximation when an exact solution is impossible, too expensive, or impractical to calculate.
- Professor Rosen says the final has seven questions, of which students choose five, and one question will ask them to simulate a game.
- Potential examples include a simple turn-taking game, Monopoly doubles and jail rules, or dice-based hit chances from Dungeons & Dragons-style systems.
- In the Monty Hall problem, a contestant chooses one of three doors, and the host opens another door that he knows hides a goat.
- Switching wins when the original choice was a goat, which happens with probability 2/3; staying wins only when the original choice was the car, with probability 1/3.
- The host's informed choice means the remaining unopened door does not simply have a 1/2 chance, despite two doors remaining.
- The million-door version makes the logic intuitive: after the host eliminates all but the contestant's door and one other, switching is strongly favored.
- Simpson's paradox occurs when comparisons within separate groups reverse after the data are combined.
- Professor Rosen uses David Justice and Derek Jeter batting averages across 1995 and 1996 to show how season-by-season rankings can differ from the combined ranking.
- The paradox matters when interpreting evidence such as possible gender bias, because isolated rates may not reflect the aggregate result.
- The Python Monty Hall simulation represents two goats and one car, shuffles the doors, and compares switch and stay strategies across 10,000 trials.
- The simulation reports about 66% wins for switching and 33% for staying, matching the theoretical probabilities.
- For the card game, random.sample selects three unique cards without replacement and gives results close to choosing the first three shuffled cards.
- Increasing the number of trials improves the estimate; the practical goal is enough significant digits to support the decision or match the precision needed.
Transcript excerpt
0:00 Let's start recording. So, there's a couple things we need to check out for the day. Um, first things first is let's talk about our upcoming homework. We're going to talk about um quite a number of things and then we'll have fun, actual fun in my opinion, but my opinion I find is quite different than everybody else's. So, >> card games. only if you want to lose. >> All right. So, first out and foremost, I have sent out a list of previously a previous free app perusal. You can find this in announcements. It should have hit your email. Uh it is uh a list of best projects. Um these are projects
0:51 that in previous semesters, like a bunch of different previous semesters, so not all at once. bunch of previous semesters that have basically uh earned a 100, so were exempt from the final exam. What it is is that like I mark for ease of being able to tell whether or not you're exempt, I mark your your score as 100. Um so these are so there I've went ahead and like um split them up. For instance, a bunch of we have a bunch of science-based ones. Um, we have some art based projects like this one done in turtle. This one was a guitar a guitar plugin. This one did uh bad apple in using asi art which was pretty awesome for those of you who are not familiar. Um, basically they are two
1:40 kind of programs used as if if it's a computer. Uh, so first off um like can run Doom Right. It's a bit of a meme uh because it can run on pretty much any any screen or any processor, right? Um yeah, it runs Doom. It's a Wikipedia
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Professor Rosen.