Solving an Impossible Riddle with Code
HTML-код
- Опубликовано: 4 июн 2024
- 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...
* RUclips: youtube.com/@robmulla?sub_con...
* Discord: / discord
* Twitch: / medallionstallion_
* Twitter: / rob_mulla
* Kaggle: www.kaggle.com/robikscube
#python #numpy #simulation #riddles
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
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!
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
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.
I’m from this video too! I was looking for a computer simulation to solve this riddle for good.
@@marc-andremaillet5893 awesome. Hopefully you found the video helpful.
@@robmulla Yes thanks!
Im absolutely loving the diversity of tutorials!
Thanks Rob!
Thanks so much! Trying something somewhat different in this tutorial. I’ve been enjoying your new content too!
Like Ritvik Rastogi said, these type of problem solving videos are fantastic. They're engaging, challenging and rewarding.
Glad you like them! This was probably the most fun I've had making a video because I think the riddle is so interesting.
I learn a lot from your videos. Thanks for spending time to create these content.
This makes me so happy 🤗 thanks for watching.
Absolutely beautiful! Got to love a good mix of data science and graph theory :)
Glad you enjoyed it!
Amazing! Awesome video, you’ve inspired me to simulate a similar problem myself
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.
THIS IS LITERALLY THE BEST THING , I ABSOLUTELY LOVE IT, THANK YOU SO MUCH. PLEASE CONTINUE MAKING MORE VIDEOS. YOU HAVE MY SUBSCRIBTION ❤❤
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!
this video is a gem
Thanks 🙌
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.
Great catch. Do you think it messed up the output? Can you point me to the timestamp?
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.
dude you're unbelievable this is so good
Thanks 🤗
Great and unexpected video! 👏👏
It’s a little different than my other videos. Glad you liked it!
this really is wild; good to see in hard sim, not just equations.
Glad you enjoyed it. Had a lot of fun making this video.
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
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.
Loved the vídeo!!!
Glad you liked it Levy! Thanks the comment
Deserves to be seen in tops
Thanks! I’m happy with this video.
Great video!
Thanks so much for watching. Share with a friend 😀
Very good tutorial. In the for-loop @7:38, shouldn't you pass prisoner to the strategy function instead of prisoner_number?
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?
@@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
@@robmulla actually, I see you have corrected this on kaggle to "correct = strategy(prisoner_number=prisoner, boxes=boxes)"
@@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
Hi in which python environment did you do this? :)
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.
Great.
Glad you liked this video. It’s one of my favorites that I’ve made even though it’s not very popular.
Why don't you just use `list(range(100))`?
Yea that would’ve been cleaner.
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.
Great points. I’d love any suggestions you have for ways the code could be improved. Looking to learn!
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
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.
return prisoner_number in prisoner_choices
Love it. Much better than my code and more pythonic. It might be less readable for newbies but maybe not.