Solving an Impossible Riddle with Code

  Рет қаралды 7,363

Rob Mulla

Rob Mulla

Күн бұрын

In this video I write code to simulate the 100 prisoner riddle problem with python. This riddle was was covered in Veritasium's amazing video here: • The Riddle That Seems ...
The notebook code can be found here: www.kaggle.com/code/robikscub...
Timeline:
00:00 Impossible Riddle
01:00 The Riddle
02:13 Simulating the Boxes
04:53 Random Strategy
11:18 Loop Strategy
15:03 Graph Network
21:06 Longest Loop
Follow me on twitch for live coding streams: / medallionstallion_
My other videos:
Speed Up Your Pandas Code: • Make Your Pandas Code ...
Speed up Pandas Code: • Make Your Pandas Code ...
Intro to Pandas video: • A Gentle Introduction ...
Exploratory Data Analysis Video: • Exploratory Data Analy...
Working with Audio data in Python: • Audio Data Processing ...
Efficient Pandas Dataframes: • Speed Up Your Pandas D...
* KZbin: youtube.com/@robmulla?sub_con...
* Discord: / discord
* Twitch: / medallionstallion_
* Twitter: / rob_mulla
* Kaggle: www.kaggle.com/robikscube
#python #numpy #simulation #riddles

Пікірлер: 57
@ritvikrastogi4912
@ritvikrastogi4912 Жыл бұрын
Hi Rob, Greetings from India I really love your content and for this tutorial, I can not even put into words how much I liked it I'm really inspired and will try out to simulate more such mathematical problems Thanks a lot for inspiring a lot of individuals like myself
@robmulla
@robmulla Жыл бұрын
Hey Ritvik - I'm so glad you found this tutorial helpful. I think that doing simulations like this can be really fun. I think it's great that you are going to do similar simulations. Please share the link to this video with anyone else you think might enjoy it!
@H99x2
@H99x2 Жыл бұрын
After watching that Veritasium video when it was just released I thought to myself "I wish I could code this up in Python.." But since I just started learning it, I couldn't. This video is exactly what I need! Thanks Rob
@robmulla
@robmulla Жыл бұрын
That's awesome! Glad to hear I wasn't the only one thinking this. Please share this with anyone else you think would like to learn how to code it in python.
@marc-andremaillet5893
@marc-andremaillet5893 Жыл бұрын
I’m from this video too! I was looking for a computer simulation to solve this riddle for good.
@robmulla
@robmulla Жыл бұрын
@@marc-andremaillet5893 awesome. Hopefully you found the video helpful.
@marc-andremaillet5893
@marc-andremaillet5893 Жыл бұрын
@@robmulla Yes thanks!
@ChaiTimeDataScience
@ChaiTimeDataScience Жыл бұрын
Im absolutely loving the diversity of tutorials! Thanks Rob!
@robmulla
@robmulla Жыл бұрын
Thanks so much! Trying something somewhat different in this tutorial. I’ve been enjoying your new content too!
@ThePaintingpeter
@ThePaintingpeter Жыл бұрын
Like Ritvik Rastogi said, these type of problem solving videos are fantastic. They're engaging, challenging and rewarding.
@robmulla
@robmulla Жыл бұрын
Glad you like them! This was probably the most fun I've had making a video because I think the riddle is so interesting.
@davoodastaraky7608
@davoodastaraky7608 Жыл бұрын
I learn a lot from your videos. Thanks for spending time to create these content.
@robmulla
@robmulla Жыл бұрын
This makes me so happy 🤗 thanks for watching.
@ronbzalen
@ronbzalen Жыл бұрын
Absolutely beautiful! Got to love a good mix of data science and graph theory :)
@robmulla
@robmulla Жыл бұрын
Glad you enjoyed it!
@md.sakiburrahman4409
@md.sakiburrahman4409 Жыл бұрын
THIS IS LITERALLY THE BEST THING , I ABSOLUTELY LOVE IT, THANK YOU SO MUCH. PLEASE CONTINUE MAKING MORE VIDEOS. YOU HAVE MY SUBSCRIBTION ❤❤
@robmulla
@robmulla Жыл бұрын
I'm so glad you like it. It's personally the favorite video I've made even though it's not the most popular. Thanks!
@reubenthomas1033
@reubenthomas1033 Жыл бұрын
Amazing! Awesome video, you’ve inspired me to simulate a similar problem myself
@robmulla
@robmulla Жыл бұрын
So happy to hear that. My goal is to inspire viewers to explore what’s possible with data science so I’m especially glad to hear you are going to take action.
@EVL624
@EVL624 Жыл бұрын
Hey, when you create the try_strategy() function you loop over the prisoners, but don't actually use the resulting values from the loop. The looping variable is called prisoner, but you are inserting prisoner_number into the strategy() function. The reason you don't get an error is that prisoner_number is still stored in the global scope from when you assigned prisoner_number = 1 earlier.
@robmulla
@robmulla Жыл бұрын
Great catch. Do you think it messed up the output? Can you point me to the timestamp?
@EVL624
@EVL624 Жыл бұрын
It should intuitively increase the winning rate slightly since we are repeatedly looking at the same prisoner 100 times, meaning that if prisoner 1 never finds their number the simulation results in a loss (which it should have if it was implemented correctly too), but if prisoner 1 does find their number, the simulation always results in a win since the same condition is just checked 100 times (this would not be the case if it was implemented correctly, since prisoner 1 could find their number, while some other prisoner does not, resulting in a loss). The timestamp is around 7:30 Edit: My reasoning is wrong for the random strategy since you always choose a random box the result should not be impacted. I will have another think about the loop strategy as well.
@realdriss0
@realdriss0 Жыл бұрын
this video is a gem
@robmulla
@robmulla Жыл бұрын
Thanks 🙌
@gustavojuantorena
@gustavojuantorena Жыл бұрын
Great and unexpected video! 👏👏
@robmulla
@robmulla Жыл бұрын
It’s a little different than my other videos. Glad you liked it!
@louisvuittondonvg9040
@louisvuittondonvg9040 Жыл бұрын
dude you're unbelievable this is so good
@robmulla
@robmulla Жыл бұрын
Thanks 🤗
@ronin6158
@ronin6158 Жыл бұрын
this really is wild; good to see in hard sim, not just equations.
@robmulla
@robmulla Жыл бұрын
Glad you enjoyed it. Had a lot of fun making this video.
@Levy957
@Levy957 Жыл бұрын
Loved the vídeo!!!
@robmulla
@robmulla Жыл бұрын
Glad you liked it Levy! Thanks the comment
@dangalimov7435
@dangalimov7435 Жыл бұрын
Deserves to be seen in tops
@robmulla
@robmulla Жыл бұрын
Thanks! I’m happy with this video.
@TheThunder005
@TheThunder005 Жыл бұрын
Great video!
@robmulla
@robmulla Жыл бұрын
Thanks so much for watching. Share with a friend 😀
@noahcollin9532
@noahcollin9532 Жыл бұрын
Great content! 👍 How do you get your notebook to tell you about function calls? @5:17 You typed "np.random.choice" and a little window popped up telling you what parameters are expected. How do you enable that functionality? Thanks
@robmulla
@robmulla Жыл бұрын
Thanks for watching! This is built into jupyter you just need to be within the function and type shift-tab. I believe it’s using something called Jedi in the backend you can search about.
@philtoa334
@philtoa334 Жыл бұрын
Great.
@robmulla
@robmulla Жыл бұрын
Glad you liked this video. It’s one of my favorites that I’ve made even though it’s not very popular.
@jonasherseth5306
@jonasherseth5306 Жыл бұрын
Very good tutorial. In the for-loop @7:38, shouldn't you pass prisoner to the strategy function instead of prisoner_number?
@robmulla
@robmulla Жыл бұрын
Thanks for the feedback. So glad you liked it. Oh no, did I mess something up? I looked at the time stamp you linked but I think you might be referring to a different part?
@jonasherseth5306
@jonasherseth5306 Жыл бұрын
@@robmulla in the for loop in the try_strategy function, you have "correct = strategy(prisoner_number, boxes)". I think the should be "correct = strategy(prisoner, boxes"... But I might be mistaken
@jonasherseth5306
@jonasherseth5306 Жыл бұрын
@@robmulla actually, I see you have corrected this on kaggle to "correct = strategy(prisoner_number=prisoner, boxes=boxes)"
@robmulla
@robmulla Жыл бұрын
@@jonasherseth5306 nice catch. I remember having to edit out a part where I fixed a bug while recording the video so you may have caught it before I did! Thanks for watching
@ulf594
@ulf594 Жыл бұрын
Hi in which python environment did you do this? :)
@robmulla
@robmulla Жыл бұрын
Hey. I’m coding in this video in a jupyterlab environment, however I’ve also posted a link to the Kaggle notebook version in the description. Check out my video on jupyter to get more details on my setup.
@Jakub1989YTb
@Jakub1989YTb Жыл бұрын
6:25 .. just use `return prisoner_number in prisoner_choices` .. You seem to know what you are doing, but it lacks the final pythonic touch. This video is full of small antipatterns.
@robmulla
@robmulla Жыл бұрын
Great points. I’d love any suggestions you have for ways the code could be improved. Looking to learn!
@Jakub1989YTb
@Jakub1989YTb Жыл бұрын
Why don't you just use `list(range(100))`?
@robmulla
@robmulla Жыл бұрын
Yea that would’ve been cleaner.
@qwang3118
@qwang3118 11 ай бұрын
The problem is interesting, but the presentation is misleading and confusing. It is NOT that prisoners have 31.2% chance to be freed. 31.2% chance is for the map f: Box Labels - -> Prisoner's # to be good, in the sense that all cycle lengths of f
@robmulla
@robmulla 11 ай бұрын
Thanks for your thoughtful and detailed comment. I'm going to need to read it a few more times to fully understand. It sounds like you have a very strong understanding of this problem. I learned it from the channel @veritasium who had a video about it. Have you seen that video? Does it also make the same mistake or is it just something I didn't explain well in my video. Interested to hear your thoughts.
@snippletrap
@snippletrap Жыл бұрын
return prisoner_number in prisoner_choices
@robmulla
@robmulla Жыл бұрын
Love it. Much better than my code and more pythonic. It might be less readable for newbies but maybe not.
Do these Pandas Alternatives actually work?
20:19
Rob Mulla
Рет қаралды 14 М.
Make Your Pandas Code Lightning Fast
10:38
Rob Mulla
Рет қаралды 175 М.
Black Magic 🪄 by Petkit Pura Max #cat #cats
00:38
Sonyakisa8 TT
Рет қаралды 32 МЛН
[柴犬ASMR]曼玉Manyu&小白Bai 毛发护理Spa asmr
01:00
是曼玉不是鳗鱼
Рет қаралды 50 МЛН
100😭🎉 #thankyou
00:28
はじめしゃちょー(hajime)
Рет қаралды 47 МЛН
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 258 М.
My response to being reverse-Dereked
8:36
Matt_Parker_2
Рет қаралды 609 М.
Making Minecraft from scratch in 48 hours (NO GAME ENGINE)
16:38
Speed Up Your Pandas Dataframes
11:15
Rob Mulla
Рет қаралды 67 М.
The Ultimate Coding Setup for Data Science
17:35
Rob Mulla
Рет қаралды 103 М.
when earth evolves into an impossible shape
15:44
GrayStillPlays
Рет қаралды 6 МЛН
Video Data Processing with Python and OpenCV
32:05
Rob Mulla
Рет қаралды 65 М.
Monty Hall Problem - Numberphile
5:30
Numberphile
Рет қаралды 4,4 МЛН
Black Magic 🪄 by Petkit Pura Max #cat #cats
00:38
Sonyakisa8 TT
Рет қаралды 32 МЛН