9.3: Genetic Algorithm: Shakespeare Monkey Example – The Nature of Code

Part 3 of the Genetic Algorithm series is dedicated to the Shakespeare Monkey Example. In this video, I use the evolutionary concepts from the previous video to compute a problem that a brute force algorithm wouldn’t be able to solve.

Support this channel on Patreon:

Send me your questions and coding challenges!:


Links discussed in this video:
The Nature of Code:
Shakespeare Monkey Theorem:

Source Code for the Video Lessons:


For More Genetic Algorithm videos:

For More Nature of Code videos:

Help us caption & translate this video!






23 responses to “9.3: Genetic Algorithm: Shakespeare Monkey Example – The Nature of Code”

  1. ispete Avatar

    Has anyone rewritten this in Python? I've written a few versions. But, my best version still takes thousands of generations to solve "To be or not to be." I don't know what I'm missing. Would love to see others' code.

  2. Mark Littlewood Avatar

    Excellent demo this, really gives students a feel for what the tweek parameters are and what effect they can have

  3. mrrubikscubeman Avatar

    Looks exactly like the end of Wargames

  4. Conner Campbell Avatar

    I open the program in firefox.. & it doesnt show my phrase or my stats below..?? Any help

  5. Gary P. Avatar

    Could you imagine if a genetic algorithm also ran a genetic algorithm inside of it that discovered the most efficient max population as it goes :-*

  6. kraay89 Avatar

    Is it safe to say that if your population is (way) bigger than the number of variables in your question you don't need mutation? Your example seemed to indicate that at around 5:00

  7. Maxine Lyu Avatar

    man gotta say I really enjoy your style of teaching! so entertaining at the same time insightful XD two thubs up!

  8. KillerFrid [CS:GO] Avatar

    Where can i find the code he uses?

  9. RedsBoneStuff Avatar

    To be Jr noE tRFbe.

  10. corentinvv Avatar

    Can we say Genetic Algorithm is artificial intelligence ?

  11. michieb1231 Avatar

    hey change do what i did and change the code a little bit and make it so it searches for: to be an idiot you must be smart

  12. otacon1024 Avatar

    7:28 The expression you're looking for is "tear the mask off nature and stare at the face of God" 😀

  13. KD Chen Avatar

    I almost died at the Norwegian part

  14. devesh bharadwaj Avatar

    What coding language have you used here?

  15. Dude7469 Avatar

    I think you wanted to get away from that "boring soon-to-be-corpse professor" – kind, but this amount of energy might be a bit too much.

    You can boost book sales by trying to appeal to masses (find middle ground). Who doesn't want to be successful in their sales?

    Edit: One way to keep that energy amount but be more appealing is to ask questions enthusiastically. "And as we can see, 100% mutation rate leads to utter garbage. Why, why does this happen?". You obviously know the answer, but it's a way to be energetic and try to immense the viewer. After all, we can passively watch these videos without further thinking, but questions promote thinking.

  16. oo0O0 Avatar

    It was the best of times, it was the blurst of times.

  17. Matthew SE Avatar

    I was thinking, and it would be really meta to make a genetic algorithm which produces the highest average fitness based off of total population and mutation rate. And then do the same thing with the best of that set. Idk, it just made me think.

  18. Spectron Avatar

    I made a similar GA, But you could type the sentence you wanted, and I used the letter's position in the alphabet to calculate the fitness, and mutated by going up or down, worked pretty well… Good video anyway 🙂

  19. Kyle Amoroso Avatar

    I was inspired by your last video about this and made my own version of this! Then I tried thinking of using this method for solving a nonogram puzzle, but I couldn't figure out what would determine the fitness. Maybe an example with Sudoku would be cool to see.

  20. Orange Juice Avatar

    Can you make C# tutorials because you make amazing videos.

Leave a Reply

Your email address will not be published. Required fields are marked *