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

Комментарии • 57

  • @ritvikrastogi4912
    @ritvikrastogi4912 Год назад +8

    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  Год назад +1

      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 Год назад +6

    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  Год назад +1

      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 Год назад +1

      I’m from this video too! I was looking for a computer simulation to solve this riddle for good.

    • @robmulla
      @robmulla  Год назад +1

      @@marc-andremaillet5893 awesome. Hopefully you found the video helpful.

    • @marc-andremaillet5893
      @marc-andremaillet5893 Год назад

      @@robmulla Yes thanks!

  • @ChaiTimeDataScience
    @ChaiTimeDataScience Год назад +3

    Im absolutely loving the diversity of tutorials!
    Thanks Rob!

    • @robmulla
      @robmulla  Год назад +1

      Thanks so much! Trying something somewhat different in this tutorial. I’ve been enjoying your new content too!

  • @ThePaintingpeter
    @ThePaintingpeter Год назад +1

    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 Год назад +2

    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 Год назад +1

    Absolutely beautiful! Got to love a good mix of data science and graph theory :)

    • @robmulla
      @robmulla  Год назад

      Glad you enjoyed it!

  • @reubenthomas1033
    @reubenthomas1033 Год назад +1

    Amazing! Awesome video, you’ve inspired me to simulate a similar problem myself

    • @robmulla
      @robmulla  Год назад +1

      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.

  • @md.sakiburrahman4409
    @md.sakiburrahman4409 Год назад +1

    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  Год назад +1

      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!

  • @realdriss0
    @realdriss0 Год назад +2

    this video is a gem

  • @EVL624
    @EVL624 Год назад +3

    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.

  • @louisvuittondonvg9040
    @louisvuittondonvg9040 Год назад +1

    dude you're unbelievable this is so good

  • @gustavojuantorena
    @gustavojuantorena Год назад +1

    Great and unexpected video! 👏👏

    • @robmulla
      @robmulla  Год назад +1

      It’s a little different than my other videos. Glad you liked it!

  • @ronin6158
    @ronin6158 Год назад +1

    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.

  • @noahcollin9532
    @noahcollin9532 Год назад +1

    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  Год назад +2

      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.

  • @Levy957
    @Levy957 Год назад +1

    Loved the vídeo!!!

    • @robmulla
      @robmulla  Год назад

      Glad you liked it Levy! Thanks the comment

  • @dangalimov7435
    @dangalimov7435 Год назад +1

    Deserves to be seen in tops

    • @robmulla
      @robmulla  Год назад

      Thanks! I’m happy with this video.

  • @TheThunder005
    @TheThunder005 Год назад +1

    Great video!

    • @robmulla
      @robmulla  Год назад +1

      Thanks so much for watching. Share with a friend 😀

  • @jonasherseth5306
    @jonasherseth5306 Год назад +2

    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 Год назад +1

      @@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 Год назад +2

    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.

  • @philtoa334
    @philtoa334 Год назад +1

    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.

  • @Jakub1989YTb
    @Jakub1989YTb Год назад +2

    Why don't you just use `list(range(100))`?

    • @robmulla
      @robmulla  Год назад

      Yea that would’ve been cleaner.

  • @Jakub1989YTb
    @Jakub1989YTb Год назад +3

    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!

  • @qwang3118
    @qwang3118 11 месяцев назад +1

    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 Год назад +1

    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.