Тёмный

Solving an Impossible Riddle with Code 

Rob Mulla
Подписаться 169 тыс.
Просмотров 7 тыс.
50% 1

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...
* RU-vid: youtube.com/@robmulla?sub_con...
* Discord: / discord
* Twitch: / medallionstallion_
* Twitter: / rob_mulla
* Kaggle: www.kaggle.com/robikscube
#python #numpy #simulation #riddles

Опубликовано:

 

5 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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.
@realdriss0
@realdriss0 Год назад
this video is a gem
@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.
@louisvuittondonvg9040
@louisvuittondonvg9040 Год назад
dude you're unbelievable this is so good
@robmulla
@robmulla Год назад
Thanks 🤗
@gustavojuantorena
@gustavojuantorena Год назад
Great and unexpected video! 👏👏
@robmulla
@robmulla Год назад
It’s a little different than my other videos. Glad you liked it!
@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.
@Levy957
@Levy957 Год назад
Loved the vídeo!!!
@robmulla
@robmulla Год назад
Glad you liked it Levy! Thanks the comment
@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.
@TheThunder005
@TheThunder005 Год назад
Great video!
@robmulla
@robmulla Год назад
Thanks so much for watching. Share with a friend 😀
@dangalimov7435
@dangalimov7435 Год назад
Deserves to be seen in tops
@robmulla
@robmulla Год назад
Thanks! I’m happy with this video.
@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 Год назад
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
Просмотров 14 тыс.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Final increíble 😱
00:39
Просмотров 27 млн
АКАДЕМИК ВОРУЕТ СНЕГ?!
00:50
Просмотров 204 тыс.
Make Your Pandas Code Lightning Fast
10:38
Просмотров 176 тыс.
My response to being reverse-Dereked
8:36
Просмотров 609 тыс.
Can you fit a whole game into a QR code?
20:03
Просмотров 8 млн
Monty Hall Problem - Numberphile
5:30
Просмотров 4,4 млн
7 Python Data Visualization Libraries in 15 minutes
15:03