title
Coding Challenge 170: The Monty Hall Problem

description
It's the Monty Hall Problem! In JavaScript! With p5.js! Yes, you really double your chances of winning by switching doors. I hope to convince you of this in this video! https://editor.p5js.org/codingtrain/sketches/pLW3_PNDM p5.js Web Editor Sketches: 🕹ī¸ Monty Hall: https://editor.p5js.org/codingtrain/sketches/pLW3_PNDM 🕹ī¸ Monty Hall (variable speed and doors): https://editor.p5js.org/codingtrain/sketches/PVuN7NPjj GitHub Repo and Demo: đŸ’ģ Repo: https://github.com/CodingTrain/Monty-Hall đŸ’ģ Demo: https://codingtrain.github.io/Monty-Hall/ đŸŽĨ Previous video: https://youtu.be/_H9JIwWP7HQ?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH đŸŽĨ All videos: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH Links discussed in this video: 🔗 Game Show Problem, Ask Marilyn, Parade Magazine 1990: https://web.archive.org/web/20130121183432/http://marilynvossavant.com/game-show-problem/ 🔗 Document Object Model (DOM): https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model 🔗 CSS Basics: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics Other videos mentioned in this video: đŸŽĨ The Basics of CSS - p5.js Tutorial: https://youtu.be/zGL8q8iQSQw đŸŽĨ 8.11 - Callbacks on Multiple DOM Elements - p5.js Tutorial https://youtu.be/KeZBpeH59Q4 đŸŽĨ Local Storage in JavaScript with p5.js https://youtu.be/_SRS8b4LcZ8 Timestamps: 0:00 What is the Monty Hall Problem? 1:50 Solution for Monty Hall Problem! 6:55 Starting the Code 8:53 Centering a DIV 10:22 Callback Events 15:40 Refactoring into Functions 23:11 Adding Stats 27:04 Playing the game! 28:21 Bayes Theorem 31:45 Goodbye! 🚂 Website: http://thecodingtrain.com/ 👾 Share Your Creation! https://thecodingtrain.com/Guides/community-contribution-guide.html 🚩 Suggest Topics: https://github.com/CodingTrain/Rainbow-Topics 💡 GitHub: https://github.com/CodingTrain đŸ’Ŧ Discord: https://discord.gg/hPuGy2g 💖 Membership: http://youtube.com/thecodingtrain/join 🛒 Store: https://standard.tv/codingtrain 📚 Books: https://www.amazon.com/shop/thecodingtrain 🖋ī¸ Twitter: https://twitter.com/thecodingtrain 📸 Instagram: https://www.instagram.com/the.coding.train/ đŸŽĨ Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH đŸŽĨ Intro to Programming: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA 🔗 p5.js: https://p5js.org 🔗 p5.js Web Editor: https://editor.p5js.org/ 🔗 Processing: https://processing.org 📄 Code of Conduct: https://github.com/CodingTrain/Code-of-Conduct Editing by Mathieu Blanchette Animations by Jason Heglund Images licensed by Getty Images Music from Epidemic Sound This description was auto-generated. If you see a problem, please open an issue: https://github.com/CodingTrain/website/issues/new

detail
{'title': 'Coding Challenge 170: The Monty Hall Problem', 'heatmap': [{'end': 507.964, 'start': 482.193, 'weight': 0.917}, {'end': 545.431, 'start': 521.075, 'weight': 0.751}, {'end': 1413.34, 'start': 1391.045, 'weight': 0.857}, {'end': 1861.751, 'start': 1812.552, 'weight': 0.972}, {'end': 1917.436, 'start': 1894.936, 'weight': 0.731}], 'summary': 'Delves into the monty hall problem, explaining the counterintuitive 66.67% chance of winning by switching doors, with a p5.js simulation demonstrating a 2 out of 3 chance of winning. it also covers simulating the problem, improving game logic with javascript, and revealing a switch win rate of 68% and a stay win rate of 41%, reinforcing the math that switching has a win rate of approximately two out of three times.', 'chapters': [{'end': 100.144, 'segs': [{'end': 82.94, 'src': 'embed', 'start': 56.269, 'weight': 0, 'content': [{'end': 61.031, 'text': 'And what is the probability that the prize is behind door number two?', 'start': 56.269, 'duration': 4.762}, {'end': 68.314, 'text': "This is the classic Monty Hall problem which originated in the American television show Let's Make a Deal back in the 1970s.", 'start': 61.311, 'duration': 7.003}, {'end': 71.836, 'text': 'The answer to the problem is you should absolutely switch.', 'start': 68.514, 'duration': 3.322}, {'end': 82.94, 'text': 'If you switch, you will have a two out of three chance, a 66.6666666% chance of the prize being behind door number two.', 'start': 72.216, 'duration': 10.724}], 'summary': 'In the monty hall problem, switching doors gives a 66.67% chance of winning.', 'duration': 26.671, 'max_score': 56.269, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA56269.jpg'}], 'start': 2.041, 'title': 'The monty hall problem', 'summary': "Discusses the monty hall problem from the tv show 'let's make a deal', explaining why switching doors gives a 66.67% chance of winning, challenging the common intuition of a 50-50 chance.", 'chapters': [{'end': 100.144, 'start': 2.041, 'title': 'Monty hall problem', 'summary': "Discusses the classic monty hall problem from the american tv show 'let's make a deal', explaining why switching doors gives a 66.6666666% chance of winning the prize, and it challenges the common intuition of a 50-50 chance.", 'duration': 98.103, 'highlights': ['Switching doors gives a 66.6666666% chance of winning the prize, as opposed to the common intuition of a 50-50 chance. The probability of winning the prize by switching doors is 66.6666666%, challenging the common 50-50 intuition.', "The Monty Hall problem originated in the American television show Let's Make a Deal back in the 1970s. The Monty Hall problem has its origins in the American TV show 'Let's Make a Deal' from the 1970s.", 'Explains the counterintuitive nature of the Monty Hall problem and emphasizes why switching doors is the optimal strategy. The chapter explains the counterintuitive nature of the Monty Hall problem and advocates for switching doors as the optimal strategy.']}], 'duration': 98.103, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA2041.jpg', 'highlights': ['Switching doors gives a 66.6666666% chance of winning the prize, challenging the common 50-50 intuition.', "The Monty Hall problem originated in the American television show Let's Make a Deal back in the 1970s.", 'Explains the counterintuitive nature of the Monty Hall problem and emphasizes why switching doors is the optimal strategy.']}, {'end': 662.697, 'segs': [{'end': 295.96, 'src': 'embed', 'start': 264.705, 'weight': 0, 'content': [{'end': 265.846, 'text': 'And yes, they win.', 'start': 264.705, 'duration': 1.141}, {'end': 269.147, 'text': "There's only three ways this game can play out.", 'start': 266.146, 'duration': 3.001}, {'end': 275.23, 'text': 'The player starting by picking door number one, starting by picking door number two, or starting by picking door number three.', 'start': 269.527, 'duration': 5.703}, {'end': 281.492, 'text': 'If the player always switches, the player will win two out of three times.', 'start': 275.75, 'duration': 5.742}, {'end': 282.853, 'text': 'Think about it this way.', 'start': 281.833, 'duration': 1.02}, {'end': 286.174, 'text': "Remember, you don't know where the prizes are.", 'start': 283.313, 'duration': 2.861}, {'end': 289.336, 'text': 'You pick door number one.', 'start': 288.015, 'duration': 1.321}, {'end': 295.96, 'text': "And I'm going to say to you now well, would you like to keep door number one,", 'start': 290.717, 'duration': 5.243}], 'summary': 'If the player always switches, they will win two out of three times.', 'duration': 31.255, 'max_score': 264.705, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA264705.jpg'}, {'end': 434.007, 'src': 'embed', 'start': 389.014, 'weight': 1, 'content': [{'end': 392.456, 'text': "If you didn't pick the prize, I have to leave the one with the prize open.", 'start': 389.014, 'duration': 3.442}, {'end': 394.798, 'text': 'Would you want to switch? I think you would.', 'start': 392.716, 'duration': 2.082}, {'end': 402.562, 'text': "There's also a very specific probability analysis known as the Bayes theorem that we could apply to show this exact two out of three probability.", 'start': 395.098, 'duration': 7.464}, {'end': 407.485, 'text': 'Or in this case, it would be a 49 out of 50 probability.', 'start': 402.882, 'duration': 4.603}, {'end': 410.247, 'text': 'You have a one out of 50 chance of it being your original pick.', 'start': 407.605, 'duration': 2.642}, {'end': 414.109, 'text': 'Or if you switch, you have a 49 out of 50 chance of winning.', 'start': 410.767, 'duration': 3.342}, {'end': 421.476, 'text': "But you're probably not here wanting to listen to me drone on and on and diagram on the whiteboard about probability and the Monty Hall problem.", 'start': 414.429, 'duration': 7.047}, {'end': 434.007, 'text': 'We could build a p5.js sketch in code that simulates the Monty Hall problem, run it thousands of times, and see if my analysis proves to be correct.', 'start': 422.076, 'duration': 11.931}], 'summary': 'Monty hall problem: switching gives 49/50 chance of winning; bayes theorem analysis.', 'duration': 44.993, 'max_score': 389.014, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA389014.jpg'}, {'end': 511.167, 'src': 'heatmap', 'start': 482.193, 'weight': 0.917, 'content': [{'end': 486.117, 'text': 'And then I will pick one randomly and put the prize there.', 'start': 482.193, 'duration': 3.924}, {'end': 493.703, 'text': 'So every time I run this sketch, I see three emojis, only one of which is a train.', 'start': 489.232, 'duration': 4.471}, {'end': 497.111, 'text': "Now, of course, they're really tiny, so let's work on some designy things.", 'start': 493.803, 'duration': 3.308}, {'end': 500.638, 'text': "Let's create a CSS class.", 'start': 498.857, 'duration': 1.781}, {'end': 507.964, 'text': 'A CSS class is a way of designating a particular set of styles to be applied to any element on the webpage.', 'start': 500.719, 'duration': 7.245}, {'end': 511.167, 'text': "This isn't a full lesson about CSS, obviously.", 'start': 508.305, 'duration': 2.862}], 'summary': 'Sketch selects 1 train emoji from 3 and applies css class.', 'duration': 28.974, 'max_score': 482.193, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA482193.jpg'}, {'end': 552.469, 'src': 'heatmap', 'start': 521.075, 'weight': 0.751, 'content': [{'end': 525.238, 'text': 'But right here in the P5 web editor, I can go over to the style.css file.', 'start': 521.075, 'duration': 4.163}, {'end': 530.341, 'text': 'I can create a door class and I can start to add some properties to it.', 'start': 525.858, 'duration': 4.483}, {'end': 538.066, 'text': 'Now, what I really like to do is center those emojis in the div.', 'start': 533.883, 'duration': 4.183}, {'end': 545.431, 'text': "Thankfully, the live Twitch chat that's watching along here has given me some tips of how to do this.", 'start': 540.388, 'duration': 5.043}, {'end': 552.469, 'text': "Let's make the emojis a little bit bigger.", 'start': 550.868, 'duration': 1.601}], 'summary': 'In the p5 web editor, creating a door class and centering emojis in a div with tips from live twitch chat.', 'duration': 31.394, 'max_score': 521.075, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA521075.jpg'}], 'start': 100.144, 'title': 'Monty hall problem simulation', 'summary': 'Explores the monty hall problem through a p5.js simulation, analyzing strategies and probabilities, showing that switching doors results in a 2 out of 3 chance of winning, supported by a simulation involving 50 doors and an application of bayes theorem.', 'chapters': [{'end': 662.697, 'start': 100.144, 'title': 'Monty hall problem simulation', 'summary': 'Explores the monty hall problem through a p5.js simulation, analyzing the different strategies and probabilities of winning, ultimately showing that switching doors results in a 2 out of 3 chance of winning, supported by a simulation involving 50 doors and an application of bayes theorem.', 'duration': 562.553, 'highlights': ['The probability analysis demonstrates that if the player always switches doors, they will win two out of three times, emphasizing the advantage of switching and showcasing the 2 out of 3 probability. The probability analysis shows that if the player always switches doors, they will win two out of three times, demonstrating the advantage of switching and highlighting the 2 out of 3 probability.', 'The chapter illustrates the application of Bayes theorem in showing the 49 out of 50 probability of winning when switching doors, providing a specific quantifiable probability that supports the strategy of switching. The application of Bayes theorem demonstrates the 49 out of 50 probability of winning when switching doors, providing a specific quantifiable probability that supports the strategy of switching.', 'The p5.js simulation of the Monty Hall problem is conducted to test different theories about the proper strategy and probabilities, offering a practical means to visualize and analyze the problem. The p5.js simulation of the Monty Hall problem allows testing different theories about the proper strategy and probabilities, providing a practical means to visualize and analyze the problem.']}], 'duration': 562.553, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA100144.jpg', 'highlights': ['The probability analysis demonstrates that if the player always switches doors, they will win two out of three times, emphasizing the advantage of switching and showcasing the 2 out of 3 probability.', 'The application of Bayes theorem demonstrates the 49 out of 50 probability of winning when switching doors, providing a specific quantifiable probability that supports the strategy of switching.', 'The p5.js simulation of the Monty Hall problem allows testing different theories about the proper strategy and probabilities, providing a practical means to visualize and analyze the problem.']}, {'end': 1132.456, 'segs': [{'end': 773.639, 'src': 'embed', 'start': 734.282, 'weight': 0, 'content': [{'end': 738.725, 'text': 'so when i click i should see zero, one, two.', 'start': 734.282, 'duration': 4.443}, {'end': 743.209, 'text': "so once i've picked, i need monty hall to reveal one of the other doors.", 'start': 738.725, 'duration': 4.484}, {'end': 749.908, 'text': 'So Monty Hall needs to know which doors can they reveal.', 'start': 747.526, 'duration': 2.382}, {'end': 752.57, 'text': "We'll make a new array called options.", 'start': 750.789, 'duration': 1.781}, {'end': 765.701, 'text': "As long as it's not the door that the player picked and the prize is not the train.", 'start': 753.651, 'duration': 12.05}, {'end': 769.945, 'text': 'I can make this a little less wordy by putting the door in a separate variable.', 'start': 765.701, 'duration': 4.244}, {'end': 773.639, 'text': 'Oh, this.', 'start': 773.098, 'duration': 0.541}], 'summary': 'Creating options array for monty hall to reveal doors.', 'duration': 39.357, 'max_score': 734.282, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA734282.jpg'}, {'end': 822.142, 'src': 'embed', 'start': 796.666, 'weight': 3, 'content': [{'end': 804.072, 'text': 'But I need to check all the possibilities because if they did pick the prize, then Monty Hall can choose to reveal one of two doors.', 'start': 796.666, 'duration': 7.406}, {'end': 808.516, 'text': "But we'll pick one of the options randomly.", 'start': 806.294, 'duration': 2.222}, {'end': 810.218, 'text': "If there's just one, there's only one it can pick.", 'start': 808.556, 'duration': 1.662}, {'end': 816.58, 'text': 'and we will put in the div the actual prize itself.', 'start': 812.799, 'duration': 3.781}, {'end': 822.142, 'text': "Okay, I'm going to pick door number one, and we should see a goat appear in either door two or three.", 'start': 817.08, 'duration': 5.062}], 'summary': 'Exploring possibilities for revealing prize behind doors in monty hall problem.', 'duration': 25.476, 'max_score': 796.666, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA796666.jpg'}, {'end': 907.396, 'src': 'embed', 'start': 869.721, 'weight': 1, 'content': [{'end': 874.485, 'text': 'One button for if you want to switch doors, or a different button if you want to stay put.', 'start': 869.721, 'duration': 4.764}, {'end': 882.985, 'text': 'So when I click on any of the doors, those two buttons will now suddenly appear.', 'start': 878.103, 'duration': 4.882}, {'end': 889.988, 'text': 'Now they look a little weird here because I have this CSS display property as flex in the entire body.', 'start': 883.025, 'duration': 6.963}, {'end': 893.57, 'text': 'So probably I should make a container for the doors.', 'start': 890.448, 'duration': 3.122}, {'end': 907.396, 'text': "So I'm going to manually put in a div called doors, reference the ID with the hash symbol, put the flex display there.", 'start': 893.71, 'duration': 13.686}], 'summary': 'Adding buttons for switching doors or staying put, adjusting display with flex property.', 'duration': 37.675, 'max_score': 869.721, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA869721.jpg'}, {'end': 955.03, 'src': 'embed', 'start': 929.157, 'weight': 2, 'content': [{'end': 937.461, 'text': 'Okay Again, very crude interaction design, but now I can choose whether I want to switch or stay.', 'start': 929.157, 'duration': 8.304}, {'end': 943.084, 'text': "This is also maybe a good moment for me to, now that I've got some code worked out, kind of refactor it.", 'start': 937.921, 'duration': 5.163}, {'end': 950.548, 'text': "Like maybe it would be nice to look at the code to see there's a pick function, a reveal function, a switch function, and then a win function.", 'start': 943.124, 'duration': 7.424}, {'end': 955.03, 'text': 'Right now I only have a reveal function, which is kind of doing both of these first two steps.', 'start': 950.848, 'duration': 4.182}], 'summary': 'Crude design allows choice to switch or stay, considering refactoring code for pick, reveal, switch, and win functions.', 'duration': 25.873, 'max_score': 929.157, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA929157.jpg'}, {'end': 1132.456, 'src': 'embed', 'start': 1101.981, 'weight': 4, 'content': [{'end': 1105.004, 'text': "I'm going to make this blue just to show that I've selected it.", 'start': 1101.981, 'duration': 3.023}, {'end': 1106.225, 'text': 'Green meaning I won.', 'start': 1105.064, 'duration': 1.161}, {'end': 1109.048, 'text': 'Pick this door.', 'start': 1108.307, 'duration': 0.741}, {'end': 1110.749, 'text': "I'm going to switch.", 'start': 1109.668, 'duration': 1.081}, {'end': 1112.171, 'text': 'And I won.', 'start': 1111.67, 'duration': 0.501}, {'end': 1115.354, 'text': "And let's get rid of the blue after I switch.", 'start': 1112.811, 'duration': 2.543}, {'end': 1120.512, 'text': 'I think I have everything now.', 'start': 1119.232, 'duration': 1.28}, {'end': 1121.833, 'text': "I'm going to pick a door.", 'start': 1120.952, 'duration': 0.881}, {'end': 1123.613, 'text': "I'm going to switch.", 'start': 1122.673, 'duration': 0.94}, {'end': 1124.894, 'text': 'And I lost.', 'start': 1124.233, 'duration': 0.661}, {'end': 1126.294, 'text': "I'm going to play again.", 'start': 1125.374, 'duration': 0.92}, {'end': 1128.334, 'text': "I'm going to pick a door.", 'start': 1126.314, 'duration': 2.02}, {'end': 1129.715, 'text': "I'm going to switch.", 'start': 1128.875, 'duration': 0.84}, {'end': 1131.215, 'text': 'And I won.', 'start': 1130.595, 'duration': 0.62}, {'end': 1132.456, 'text': "It's working.", 'start': 1131.875, 'duration': 0.581}], 'summary': 'Out of 3 attempts, switching doors led to winning twice in the game scenario.', 'duration': 30.475, 'max_score': 1101.981, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1101981.jpg'}], 'start': 663.057, 'title': 'Simulating monty hall problem and designing interactive door game', 'summary': 'Covers simulating the monty hall problem, tracking game state, determining doors revealed, and picking doors, as well as designing an interactive door game with buttons for switching doors, code refactoring, and functionality testing.', 'chapters': [{'end': 849.615, 'start': 663.057, 'title': 'Monty hall problem simulation', 'summary': 'Outlines the process of simulating the monty hall problem, using a variable to keep track of the game state, determining the doors to be revealed by monty hall, and indicating the door that was picked during the simulation.', 'duration': 186.558, 'highlights': ["The chapter outlines the process of simulating the Monty Hall problem, using a variable to keep track of the game state. The variable 'state' is used to keep track of the game state, starting with the 'pick' state where the player picks a door.", 'Determining the doors to be revealed by Monty Hall. Monty Hall reveals a door with a goat behind it, excluding the door picked by the player and the door with the prize.', 'Indicating the door that was picked during the simulation. The simulation includes a feature to indicate which door was picked by the player, enhancing the interactive experience.']}, {'end': 1132.456, 'start': 851.408, 'title': 'Interactive door game design', 'summary': "Discusses designing an interactive door game, including adding buttons for switching doors, refactoring code, and testing the game's functionality.", 'duration': 281.048, 'highlights': ["Adding buttons for switching doors The chapter discusses adding buttons for the player to switch or stay put when choosing doors, enhancing the game's interactivity.", "Refactoring code and creating functions for game actions The author explains the need to refactor the code to separate functions for picking, revealing, switching doors, and checking for a win, aiming to improve the game's structure and functionality.", "Testing the game's functionality The author describes testing the game by picking and switching doors multiple times, showcasing the successful functionality of the game."]}], 'duration': 469.399, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA663057.jpg', 'highlights': ['The chapter outlines the process of simulating the Monty Hall problem, using a variable to keep track of the game state.', "Adding buttons for switching doors enhances the game's interactivity.", "Refactoring code and creating functions for game actions aims to improve the game's structure and functionality.", 'Determining the doors to be revealed by Monty Hall is a crucial aspect of the simulation.', "Testing the game's functionality by picking and switching doors multiple times showcases its successful functionality.", 'Indicating the door that was picked during the simulation enhances the interactive experience.']}, {'end': 1377.551, 'segs': [{'end': 1216.333, 'src': 'embed', 'start': 1153.066, 'weight': 0, 'content': [{'end': 1159.567, 'text': 'The reason why this is important is that picking event should only happen if the state is pick.', 'start': 1153.066, 'duration': 6.501}, {'end': 1166.73, 'text': "So now if I were to click again in the middle of the game, it wouldn't change anything that's happening.", 'start': 1162.108, 'duration': 4.622}, {'end': 1168.03, 'text': 'This code would not execute.', 'start': 1166.79, 'duration': 1.24}, {'end': 1171.662, 'text': 'I am probably overusing global variables here,', 'start': 1168.661, 'duration': 3.001}, {'end': 1178.624, 'text': 'but it would be helpful to actually have these buttons be global variables that I could just show or hide as needed.', 'start': 1171.662, 'duration': 6.962}, {'end': 1192.428, 'text': "So I'm actually going to take these and put them in setup, hide them, and then just show them when it's time to prompt the user.", 'start': 1179.784, 'duration': 12.644}, {'end': 1201.421, 'text': 'Then after the player has either chosen to switch or stay, I can hide those buttons again.', 'start': 1195.816, 'duration': 5.605}, {'end': 1207.225, 'text': 'Pick a door, switch, and I won.', 'start': 1204.263, 'duration': 2.962}, {'end': 1210.248, 'text': "Let's add some CSS for the you win message.", 'start': 1207.946, 'duration': 2.302}, {'end': 1216.333, 'text': "And let's create a play again button.", 'start': 1213.29, 'duration': 3.043}], 'summary': 'Code will only execute if state is pick, using global variables for buttons and adding css for you win message.', 'duration': 63.267, 'max_score': 1153.066, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1153066.jpg'}], 'start': 1132.496, 'title': 'Improving game logic with javascript', 'summary': 'Discusses the significance of changing state variables, employing global variables, integrating css for user interface, and the necessity of resetting the game after each play in the context of game logic improvement using javascript.', 'chapters': [{'end': 1377.551, 'start': 1132.496, 'title': 'Improving game logic with javascript', 'summary': 'Discusses improving game logic with javascript, including the importance of changing state variables, using global variables, adding css for user interface, and the need for resetting the game after each play.', 'duration': 245.055, 'highlights': ['Changing state variables is important for controlling game events, ensuring that certain actions occur only under specific conditions. Emphasizes the importance of changing state variables to control game events.', 'Utilizing global variables for buttons allows for easy manipulation of their visibility based on game events. Suggests the use of global variables for buttons to show or hide them as needed.', 'Adding CSS for user interface and creating a play again button enhances the visual appeal and interactivity of the game. Highlights the importance of adding CSS for user interface and implementing a play again button.', 'Resetting the game involves setting the state back to its initial value, clearing any previous game outcomes, and hiding the play again button. Emphasizes the necessity of resetting the game by setting the state back to its initial value, clearing previous outcomes, and hiding the play again button.']}], 'duration': 245.055, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1132496.jpg', 'highlights': ['Changing state variables is important for controlling game events, ensuring that certain actions occur only under specific conditions.', 'Utilizing global variables for buttons allows for easy manipulation of their visibility based on game events.', 'Adding CSS for user interface and creating a play again button enhances the visual appeal and interactivity of the game.', 'Resetting the game involves setting the state back to its initial value, clearing any previous game outcomes, and hiding the play again button.']}, {'end': 1696.924, 'segs': [{'end': 1417.863, 'src': 'heatmap', 'start': 1391.045, 'weight': 0.857, 'content': [{'end': 1398.031, 'text': "i'm ready to wrap this up i mean what i really would like to do and i'll create a version of it that just picks automatically and switches automatically,", 'start': 1391.045, 'duration': 6.986}, {'end': 1400.512, 'text': 'running it hundreds of times per second.', 'start': 1398.031, 'duration': 2.481}, {'end': 1402.653, 'text': "And I'm showing that to you right now over here.", 'start': 1400.712, 'duration': 1.941}, {'end': 1413.34, 'text': "But what I'm going to do in this video itself is just add some code to track the win rate for switching and the win rate for staying put.", 'start': 1403.194, 'duration': 10.146}, {'end': 1417.863, 'text': 'And if the math that I demonstrated at the beginning of the video is correct,', 'start': 1413.74, 'duration': 4.123}], 'summary': 'Create a version to automatically pick and switch, running hundreds of times per second, and track the win rates for switching and staying put.', 'duration': 26.818, 'max_score': 1391.045, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1391045.jpg'}, {'end': 1441.574, 'src': 'embed', 'start': 1413.74, 'weight': 1, 'content': [{'end': 1417.863, 'text': 'And if the math that I demonstrated at the beginning of the video is correct,', 'start': 1413.74, 'duration': 4.123}, {'end': 1424.827, 'text': 'we should see a win rate of approximately two out of three times for switching and one out of three times for staying put.', 'start': 1417.863, 'duration': 6.964}, {'end': 1430.089, 'text': 'So I need a variable for total plays, total switches.', 'start': 1425.327, 'duration': 4.762}, {'end': 1433.03, 'text': "Actually, I don't need the total plays.", 'start': 1431.63, 'duration': 1.4}, {'end': 1441.574, 'text': "I need to know how many times did I switch and how many times did I stay? So I'll call that total switch plays, awkward variable names.", 'start': 1433.131, 'duration': 8.443}], 'summary': 'Switching strategy yields a 2:1 win rate over staying put.', 'duration': 27.834, 'max_score': 1413.74, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1413740.jpg'}, {'end': 1585.615, 'src': 'embed', 'start': 1551.482, 'weight': 0, 'content': [{'end': 1555.785, 'text': 'The switch rate is the total switch wins divided by the total switch plays.', 'start': 1551.482, 'duration': 4.303}, {'end': 1562.91, 'text': 'The stay rate is the total stay wins divided by the total stay plays.', 'start': 1557.406, 'duration': 5.504}, {'end': 1572.357, 'text': 'Then I can use a nice template literal to display a nicely formatted message with the data that is in those variables.', 'start': 1564.511, 'duration': 7.846}, {'end': 1584.574, 'text': 'And for the win rates, I want those to appear as percentages.', 'start': 1581.673, 'duration': 2.901}, {'end': 1585.615, 'text': "So I'll multiply them by 100.", 'start': 1584.594, 'duration': 1.021}], 'summary': 'Calculate switch and stay win rates as percentages.', 'duration': 34.133, 'max_score': 1551.482, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1551482.jpg'}], 'start': 1377.551, 'title': 'Monty hall problem win rates', 'summary': 'Covers the monty hall problem, demonstrating win rates for switching and staying put through code, revealing a switch win rate of 68% and a stay win rate of 41%, reinforcing the math that switching has a win rate of approximately two out of three times, while staying put has a win rate of one out of three times.', 'chapters': [{'end': 1521.293, 'start': 1377.551, 'title': 'Monty hall problem analysis', 'summary': 'Discusses the monty hall problem and demonstrates the win rates for switching and staying put through code, aiming to prove the math that switching has a win rate of approximately two out of three times, while staying put has a win rate of one out of three times.', 'duration': 143.742, 'highlights': ['The chapter discusses the Monty Hall problem and demonstrates the win rates for switching and staying put through code. The author creates a version of the Monty Hall problem that picks automatically and switches automatically, running it hundreds of times per second to track the win rates for switching and staying put.', 'The author aims to prove the math that switching has a win rate of approximately two out of three times, while staying put has a win rate of one out of three times. The author introduces code to track the win rates for switching and staying put and expects to see a win rate of approximately two out of three times for switching and one out of three times for staying put, based on the math demonstrated at the beginning of the video.', 'The author creates variables to track the number of switch plays and stay plays, and introduces a function for staying. The author creates variables to track the total switch plays, switch wins, total stay plays, and stay wins, and introduces a function for staying, which increases the number of total stay plays before going to check for wins.']}, {'end': 1696.924, 'start': 1521.934, 'title': 'Monty hall win rates calculation', 'summary': 'Details the process of calculating and displaying win rates for the monty hall problem, with a switch win rate of 68% and a stay win rate of 41%, emphasizing the potential use of local storage and the need to address divide by zero errors.', 'duration': 174.99, 'highlights': ["The switch win rate is about 68% and the stay win rate is about 41%, indicating extra luck on both, particularly for staying. {'switch_win_rate': '68%', 'stay_win_rate': '41%'}", "The potential use of local storage is emphasized for tracking plays and the need to address divide by zero errors is mentioned. {'use_of_local_storage': True, 'divide_by_zero_errors': True}", "The need for displaying win rates as percentages and using P5 number format function to limit to two decimal places is outlined. {'display_format': 'percentages', 'decimal_places_limit': 2}"]}], 'duration': 319.373, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1377551.jpg', 'highlights': ['The switch win rate is about 68% and the stay win rate is about 41%', 'The chapter discusses the Monty Hall problem and demonstrates the win rates for switching and staying put through code', 'The author aims to prove the math that switching has a win rate of approximately two out of three times, while staying put has a win rate of one out of three times']}, {'end': 1924.282, 'segs': [{'end': 1756.292, 'src': 'embed', 'start': 1697.104, 'weight': 1, 'content': [{'end': 1700.827, 'text': 'But as long as I play one switch and one stay, the error will go away.', 'start': 1697.104, 'duration': 3.723}, {'end': 1708.996, 'text': "Before I leave you, let me attempt to tie everything I've done to Bayes' theorem.", 'start': 1701.488, 'duration': 7.508}, {'end': 1716.604, 'text': "This is the famous Bayes' probability theorem.", 'start': 1712.82, 'duration': 3.784}, {'end': 1720.228, 'text': 'Let me first address what is meant by the notation here.', 'start': 1716.864, 'duration': 3.364}, {'end': 1728.673, 'text': 'So if we say something like p of a, This is the probability of the event A occurring.', 'start': 1720.788, 'duration': 7.885}, {'end': 1737.282, 'text': "So if I'm flipping a coin and the event A isn't landing on heads, the probability of A is 50%, one out of two times.", 'start': 1728.994, 'duration': 8.288}, {'end': 1745.79, 'text': 'This notation here, PA line B, this is known as conditional probability.', 'start': 1737.682, 'duration': 8.108}, {'end': 1751.411, 'text': 'Meaning there are two events, A and B.', 'start': 1747.15, 'duration': 4.261}, {'end': 1756.292, 'text': "What's the probability of A occurring, given B occurring?", 'start': 1751.411, 'duration': 4.881}], 'summary': "Explanation of bayes' theorem and conditional probability with examples.", 'duration': 59.188, 'max_score': 1697.104, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1697104.jpg'}, {'end': 1917.436, 'src': 'heatmap', 'start': 1812.552, 'weight': 0, 'content': [{'end': 1823.003, 'text': 'The prior probability, just given nothing, no information whatsoever, that the winner, the prize is under door A, is one out of three.', 'start': 1812.552, 'duration': 10.451}, {'end': 1826.112, 'text': 'P of B.', 'start': 1825.011, 'duration': 1.101}, {'end': 1831.094, 'text': 'B is the event that Monty Hall reveals door B.', 'start': 1826.112, 'duration': 4.982}, {'end': 1838.758, 'text': "What is the probability that Monty Hall will reveal door B if the prize is under A? Well, that's 100%.", 'start': 1831.094, 'duration': 7.664}, {'end': 1848.083, 'text': '100% Because if I picked C and the prize is under A, Monty Hall has to show door B.', 'start': 1838.758, 'duration': 9.325}, {'end': 1851.064, 'text': "So that's 100% or 1.", 'start': 1848.083, 'duration': 2.981}, {'end': 1853.085, 'text': "Now we've got a slightly trickier one.", 'start': 1851.064, 'duration': 2.021}, {'end': 1861.751, 'text': "Given no information, what's the probability that Monty Hall reveals door B? So I've picked C, but I don't know.", 'start': 1853.546, 'duration': 8.205}, {'end': 1865.173, 'text': 'The prize is not necessarily under A.', 'start': 1862.271, 'duration': 2.902}, {'end': 1866.974, 'text': "We don't have that prior information.", 'start': 1865.173, 'duration': 1.801}, {'end': 1873.618, 'text': 'So the probability that Monty Hall reveals door B in this case is just a flip of a coin, 50%.', 'start': 1867.274, 'duration': 6.344}, {'end': 1876, 'text': "Maybe it's going to be A, maybe it's going to be B.", 'start': 1873.618, 'duration': 2.382}, {'end': 1878.061, 'text': "We don't have any information to tell us one or the other.", 'start': 1876, 'duration': 2.061}, {'end': 1883.606, 'text': 'So now, One times one third divided by one half.', 'start': 1878.401, 'duration': 5.205}, {'end': 1887.769, 'text': 'Guess what that is? Two thirds.', 'start': 1884.266, 'duration': 3.503}, {'end': 1894.916, 'text': 'The probability, if I started with C, that A is the winner given Monty Hall revealing B is two out of three.', 'start': 1887.95, 'duration': 6.966}, {'end': 1899.06, 'text': "And there's a lot more to be said about this kind of probability analysis.", 'start': 1894.936, 'duration': 4.124}, {'end': 1905.986, 'text': "I will include some excellent references to Bayes' theorem and the Monty Hall problem in the video's description if you want to take a look at those.", 'start': 1899.38, 'duration': 6.606}, {'end': 1911.911, 'text': 'One thing that I really missed that would be fun to try is could you make the number of doors a variable?', 'start': 1906.426, 'duration': 5.485}, {'end': 1914.694, 'text': 'So suddenly you have a version of this with 10 doors or 100 doors.', 'start': 1911.971, 'duration': 2.723}, {'end': 1917.436, 'text': 'And how many doors are revealed? Oh, so many possibilities.', 'start': 1914.734, 'duration': 2.702}], 'summary': 'The probability of winning under door a is 1 out of 3, and if monty hall reveals door b, the probability of a being the winner is 2 out of 3.', 'duration': 86.508, 'max_score': 1812.552, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1812552.jpg'}], 'start': 1697.104, 'title': "Bayes' theorem and bayesian inference", 'summary': "Explores conditional probability and bayes' theorem, illustrating the probability of an event given another event. it discusses bayesian inference in the context of the monty hall problem, emphasizing the probability of winning by switching doors to be two out of three, with references to further resources.", 'chapters': [{'end': 1756.292, 'start': 1697.104, 'title': "Bayes' theorem and conditional probability", 'summary': "Explores the concept of conditional probability and ties it to bayes' theorem, illustrating the probability of an event occurring given another event, such as the probability of a occurring given b occurs.", 'duration': 59.188, 'highlights': ['The chapter discusses the concept of conditional probability, clarifying the notation and providing an example of the probability of an event A occurring given event B occurs, such as the probability of A occurring given B occurs.', "The chapter ties the concept of conditional probability to Bayes' theorem, emphasizing the famous Bayesian probability theorem and its relevance in understanding the probability of events occurring given other events."]}, {'end': 1924.282, 'start': 1756.872, 'title': 'Bayesian inference and the monty hall problem', 'summary': 'Discusses the application of bayesian inference in the context of the monty hall problem, demonstrating the calculation of probabilities and emphasizing the probability of winning by switching doors to be two out of three, with references to further resources.', 'duration': 167.41, 'highlights': ['The probability, if I started with C, that A is the winner given Monty Hall revealing B is two out of three. Demonstrates the calculated probability of winning by switching doors to be two out of three.', 'The prior probability, just given nothing, no information whatsoever, that the winner, the prize is under door A, is one out of three. Explains the prior probability of the prize being behind a specific door when no information is available.', "Given no information, what's the probability that Monty Hall reveals door B? So I've picked C, but I don't know. The prize is not necessarily under A. We don't have that prior information. Discusses the probability of Monty Hall revealing a specific door when no prior information is available."]}], 'duration': 227.178, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/0zac-cDzJwA/pics/0zac-cDzJwA1697104.jpg', 'highlights': ['The probability of winning by switching doors to be two out of three.', "The chapter ties the concept of conditional probability to Bayes' theorem.", 'The chapter discusses the concept of conditional probability and provides an example.', 'Explains the prior probability of the prize being behind a specific door when no information is available.', 'Discusses the probability of Monty Hall revealing a specific door when no prior information is available.']}], 'highlights': ['Switching doors gives a 66.6666666% chance of winning the prize, challenging the common 50-50 intuition.', "The Monty Hall problem originated in the American television show Let's Make a Deal back in the 1970s.", 'Explains the counterintuitive nature of the Monty Hall problem and emphasizes why switching doors is the optimal strategy.', 'The probability analysis demonstrates that if the player always switches doors, they will win two out of three times, emphasizing the advantage of switching and showcasing the 2 out of 3 probability.', 'The application of Bayes theorem demonstrates the 49 out of 50 probability of winning when switching doors, providing a specific quantifiable probability that supports the strategy of switching.', 'The p5.js simulation of the Monty Hall problem allows testing different theories about the proper strategy and probabilities, providing a practical means to visualize and analyze the problem.', 'The chapter outlines the process of simulating the Monty Hall problem, using a variable to keep track of the game state.', "Adding buttons for switching doors enhances the game's interactivity.", "Refactoring code and creating functions for game actions aims to improve the game's structure and functionality.", 'Determining the doors to be revealed by Monty Hall is a crucial aspect of the simulation.', "Testing the game's functionality by picking and switching doors multiple times showcases its successful functionality.", 'Indicating the door that was picked during the simulation enhances the interactive experience.', 'Changing state variables is important for controlling game events, ensuring that certain actions occur only under specific conditions.', 'Utilizing global variables for buttons allows for easy manipulation of their visibility based on game events.', 'Adding CSS for user interface and creating a play again button enhances the visual appeal and interactivity of the game.', 'Resetting the game involves setting the state back to its initial value, clearing any previous game outcomes, and hiding the play again button.', 'The switch win rate is about 68% and the stay win rate is about 41%', 'The chapter discusses the Monty Hall problem and demonstrates the win rates for switching and staying put through code', 'The author aims to prove the math that switching has a win rate of approximately two out of three times, while staying put has a win rate of one out of three times', 'The probability of winning by switching doors to be two out of three.', "The chapter ties the concept of conditional probability to Bayes' theorem.", 'The chapter discusses the concept of conditional probability and provides an example.', 'Explains the prior probability of the prize being behind a specific door when no information is available.', 'Discusses the probability of Monty Hall revealing a specific door when no prior information is available.']}