Coding Challenge 179: Elementary Cellular Automata

Поділитися
Вставка
  • Опубліковано 15 тра 2024
  • How is nature hidden in a pile of 0s and 1s? Let's find out by coding a p5.js visualization of the Wolfram Elementary Cellular Automaton! Code: thecodingtrain.com/challenges...
    🚀 Watch this video ad-free on Nebula nebula.tv/videos/codingtrain-...
    p5.js Web Editor Sketches:
    🕹️ Wolfram Cellular Automata: editor.p5js.org/codingtrain/s...
    🕹️ Wolfram CA with color: editor.p5js.org/codingtrain/s...
    🕹️ Wolfram CA infinite scroll: editor.p5js.org/codingtrain/s...
    🕹️ 3D Grid: editor.p5js.org/codingtrain/s...
    🎥 Previous: • Coding Challenge 178: ...
    🎥 All: • Coding Challenges
    References:
    🔗 A New Kind of Science: www.wolframscience.com/nks/
    🔗 Elementary Cellular Automaton: mathworld.wolfram.com/Element...
    🔗 Pre-Order Nature of Code: nostarch.com/nature-code
    🔗 The Nature of Code: natureofcode.com
    Related Coding Challenges:
    🚂 85 The Game of Life: • Coding Challenge #85: ...
    🚂 123 Chaos Game: • Coding Challenge #123:...
    🚂 119 Binary to Decimal Conversion: • Coding Challenge #119:...
    Timestamps:
    0:00 Hello!
    2:09 What is an elementary cellular automata?
    5:41 Explaining the rulesets
    7:52 Calculating the next generation.
    10:35 Visualizing the CA
    14:25 Rule 90
    16:45 Wolfram Classification.
    19:19 Adding wrap-around
    20:37 Suggestions for variations!
    21:07 Goodbye!
    Editing by Mathieu Blanchette
    Animations by Jason Heglund
    Music from Epidemic Sound
    🚂 Website: thecodingtrain.com/
    👾 Share Your Creation! thecodingtrain.com/guides/pas...
    🚩 Suggest Topics: github.com/CodingTrain/Sugges...
    💡 GitHub: github.com/CodingTrain
    💬 Discord: thecodingtrain.com/discord
    💖 Membership: ua-cam.com/users/thecodingtrainjoin
    🛒 Store: standard.tv/codingtrain
    🖋️ Twitter: / thecodingtrain
    📸 Instagram: / the.coding.train
    🎥 Coding Challenges: • Coding Challenges
    🎥 Intro to Programming: • Start learning here!
    🔗 p5.js: p5js.org
    🔗 p5.js Web Editor: editor.p5js.org/
    🔗 Processing: processing.org
    📄 Code of Conduct: github.com/CodingTrain/Code-o...
    This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecod...
    #natureofcode #wolfram #ca #cellularautomata #binarytodecimalconversion #sierpinskitriangle #p5js #javascript

КОМЕНТАРІ • 225

  • @unchaynd7266
    @unchaynd7266 4 місяці тому +211

    babe wake up, new coding challenge just dropped

    • @joostvanrens
      @joostvanrens 4 місяці тому +5

      I told you to only wake me up for videos of cats pretending to be humans!

    • @PMA_ReginaldBoscoG
      @PMA_ReginaldBoscoG 4 місяці тому

      Thanks mate 'cause I too wanted to comment the same when this popped up in my feed🤝

    • @coding8524
      @coding8524 3 місяці тому

      Even I was going for "me time on chrome" but now coding challenge is new priority 🤣

  • @bendunselman
    @bendunselman 4 місяці тому +122

    Fond memories. Once upon a time when I was a 45 years younger hippy I programmed a 20 by 20 colored CA on an Ohio Scientific 6502 machine, photographed it and had a girl friend knit a sweater with that pattern. I wore the sweater when I graduated my physics MSc.

    • @mattshu
      @mattshu 3 місяці тому +3

      would love to know if you still have/wear that sweater

    • @bendunselman
      @bendunselman 3 місяці тому +15

      @@mattshu The sweater is long lost. Life happened. The girl friend died a couple of years ago.

    • @flameofthephoenix8395
      @flameofthephoenix8395 2 місяці тому

      Ah! I read "Food memories" instead of fond ones...

  • @SridharGajendran
    @SridharGajendran 4 місяці тому +115

    Thanks for being an amazing teacher, Dan. I am forever grateful to you.

  • @danieltornqvist6062
    @danieltornqvist6062 4 місяці тому +41

    This made me very happy, best explanation of the 255 rules I've seen.
    You go, Dan!

  • @shlazzargh
    @shlazzargh 3 місяці тому +7

    For my semester project in my computer security class a few years ago, I made a hashing algorithm (in Perl) that used CA. The initialization vector was built by iterating a CA rule 30 out to about 2000 rows and then the hash was built from applying a CA between 'chunks' of the input message (starting from the init vector). The cool thing is that a CA is really easy to calculate, but dang near impossible to figure out how many iterations you've done. So it works great for hashing :-)

  • @AhmadAlMutawa_abunoor
    @AhmadAlMutawa_abunoor 4 місяці тому +12

    I am very happy to see these coding challenges come back again... Please keep doing more of those. This one if fascinating, educational, fun to watch, and to try!

  • @arthurribeiro1452
    @arthurribeiro1452 4 місяці тому +3

    What a ride! That was absolutely FANTASTIC. Please post more Coding Challenges this year 🙏🙏🙏

  • @BarneyCodes
    @BarneyCodes 4 місяці тому +14

    Great video as always Dan! Your enthusiasm is so infectious!

  • @imaginaryangle
    @imaginaryangle 4 місяці тому +13

    Beautifully done! I love how you construct a solution from basic principles and delay optimization. It's perfect for following along!

  • @Chronozia
    @Chronozia 4 місяці тому +1

    Glad to see another instance of a Coding Challenge! I've missed this series :)

  • @zer001
    @zer001 4 місяці тому +1

    Nice to have you back and see more videos from you.

  • @kejonp9302
    @kejonp9302 4 місяці тому +2

    Finally another interesting coding challenge! thank you for doing this series. I've learnt a lot! Much love from Indonesia 🙏🏻🔥

  • @mikethetreeclimber7
    @mikethetreeclimber7 4 місяці тому

    Your humor and enthusiasm is so contagious!!!

  • @realcygnus
    @realcygnus 4 місяці тому +1

    Great ! I loved your regular old challenges.

  • @londongaz2
    @londongaz2 4 місяці тому +3

    I really enjoyed this video! I have been dabbling in cellular automata for some time and have come up with a nice 3d multi state version. Fascinating stuff! Wolfram's book now purchased!

  • @tagon35
    @tagon35 4 місяці тому +29

    It would be an interesting experiment to take the 1D cells and give them some sort of deeper memory, extending the rulesets you could have exponentially. For instance, instead of only looking at the past generation, look at the past 2 or 3 generations, if applicable.

    • @Fishpizza1212
      @Fishpizza1212 4 місяці тому +3

      Fibonacci Cellular Automata?

    • @ThePharphis
      @ThePharphis 4 місяці тому +1

      That's like adding more states, and order of states could be optional if desired. Interesting idea!

    • @PMA_ReginaldBoscoG
      @PMA_ReginaldBoscoG 4 місяці тому

      ​@@Fishpizza1212the sum of the previous 2 states modulo 2 is the present state. Dear Dan, please make this happen 😊

    • @chitlitlah
      @chitlitlah 4 місяці тому +5

      @@PMA_ReginaldBoscoG But he just taught you everything you need to know to make it happen yourself. Spring forth, grasshopper.

    • @PMA_ReginaldBoscoG
      @PMA_ReginaldBoscoG 4 місяці тому +1

      @@chitlitlah Will try to do it asap.👍

  • @pattvira
    @pattvira 4 місяці тому +2

    A new coding challenge and I’m here for it. Great video Dan!

  • @electronicgarden3259
    @electronicgarden3259 4 місяці тому +9

    When you showed us the picture of the shell with that semi random pattern I got tears in my eyes.
    I've been fascinated by fractals since I was a teen in the 80's. Read the book Chaos and looked at nature with new eyes ever since.
    There is something with the connection between pure math and nature that resonate deep inside me.

  • @dpelta
    @dpelta 2 місяці тому +3

    Here a computer science professor from Spain. Excelent and very clear videos! I hope I can convince my colleagues to teach p5.js in the 1st year programming courses

  • @cuadernoazul5958
    @cuadernoazul5958 4 місяці тому

    Its nice to have you back again!

  • @jgg75
    @jgg75 4 місяці тому

    Great video and I am so happy you are back making these 🎉

  • @matthewmorgan1715
    @matthewmorgan1715 4 місяці тому

    Oh my gosh I forgot how much I loved your videos ❤ This was excellent.

  • @thehappycoder3760
    @thehappycoder3760 4 місяці тому

    Utterly brilliant as always

  • @giant3909
    @giant3909 3 місяці тому

    In Minecraft 1.17 and before, cellular automata algorithms were used to generate random patterns when generating the world. I'm glad I stumbled on you video, it is really inspirign and now I want to code cellular automatas

  • @freddyjosereginomontalvo4667
    @freddyjosereginomontalvo4667 4 місяці тому

    I love this channel and their videos.
    Keep going.

  • @KaveendraVithana
    @KaveendraVithana 4 місяці тому +6

    Thanks for making coding fun and enjoyable. I have pre-ordered your book as an appreciation.

  • @jordannaser9549
    @jordannaser9549 Місяць тому

    This channel is so entertaining and whimsical

  • @lark3352
    @lark3352 3 місяці тому +1

    That was beyond amazing to watch.

  • @malonemakoto8462
    @malonemakoto8462 3 місяці тому +2

    This was so cool, I managed to recreate this in C++ using the qt framework. Thanks for this video!

  • @quangminhphan9088
    @quangminhphan9088 4 місяці тому +1

    I love every mathematic lesson you gave us

  • @flobiish
    @flobiish 4 місяці тому +1

    What a coincidence (for me) you posted this today as I was considering writing something similar but 2d like Conway's Life (and I just watched your Life video again yesterday). Anyways, keep up the good work. Love your channel.

  • @RicoGalassi
    @RicoGalassi 4 місяці тому

    Always a great day when Dan releases a new coding video!!!

  • @atomsmasher
    @atomsmasher 4 місяці тому

    Thank you for making these videos. I love you.

  • @Gilbe2003
    @Gilbe2003 3 місяці тому

    I startene watching your video thi summer and i was fascinated of the beauty of coding with graphics and using processing

  • @stabilini
    @stabilini 4 місяці тому

    I'm so glad you explain things so simple. I would like to see 2D version now!

  • @justind4615
    @justind4615 4 місяці тому

    Yey another great video from you! :D

  • @gudmythman
    @gudmythman 4 місяці тому

    Ive been super into these lately, you reading my mind xD

  • @kluplau
    @kluplau 4 місяці тому +1

    It's been too long Dan. Even the whistle has been collecting soo much dust that it barely works :D Nice to have you back. I will look forward to watching your videos.

  • @liukang81
    @liukang81 4 місяці тому

    It’s a great coding lesson,sir! I love it!

  • @ig4yara
    @ig4yara 4 місяці тому

    Oh my god, I love this video!!! thank you so much!!!

  • @breakplays
    @breakplays 4 місяці тому

    yeeeey, more coding challenges this year 🎉

  • @astropgn
    @astropgn 4 місяці тому

    Best channel ever! Love it

  • @thomashalverson6962
    @thomashalverson6962 4 місяці тому

    Your joy brings me joy

  • @yannickperret1586
    @yannickperret1586 4 місяці тому

    Thanks for this and happy that you'll get more time!
    I tested a variation: use rules based on 5 cells rather than 3 (2 neighborhood each side). It leads to 2^32 possible rules and generates of course more complex stuff.
    I also added color in an other way: based on the 5 cells I take the 3 firsts to compute the red value ( (value/7.)*200.+55. in order to prevent too dark colors, and it is applyed for white), the 3 next for green, and the 3 lasts for blue.

  • @sonik382
    @sonik382 4 місяці тому

    Finally back with a new Coding Challenge!!!! 🎉

  • @Elizabeth-vh6il
    @Elizabeth-vh6il 3 місяці тому

    Awesome. I actually already started doing this one back when you demoed 2D CAs because I was looking for something where the rule could be more easily inferred from the image and so reducing the state space to a single dimension and putting time on the y-axis was the solution to my problem.

  • @tythedev9582
    @tythedev9582 4 місяці тому

    Was watching your videos as a fresh Computer Science student and now still watching as a salaried Software Engineer. Your videos never fail to remind me of the fun of coding. Thanks so much!

  • @AnM-of4wz
    @AnM-of4wz 4 місяці тому

    You don't have to say sorry about your way to code. We all know that you're pro. Thank you. That blow my mind!

  • @gerhardbrauckmann2908
    @gerhardbrauckmann2908 4 місяці тому

    Amazing stuff!!! Thank you!

  • @tsarprince
    @tsarprince 4 місяці тому

    Wohooo back to coding challenges🎉

  • @duality4y
    @duality4y 4 місяці тому +1

    I really love your book i used it like 6 years back maybe to have some fun coding :)

  • @_rlb
    @_rlb 4 місяці тому +4

    I got my stickers in the mail earlier this week! I know it's off topic but I'm so excited 😊

  • @lumotroph
    @lumotroph 4 місяці тому

    Incredible!

  • @ethanmilton7083
    @ethanmilton7083 3 місяці тому

    I've been trying to find a way to do image compression with cellular automata for like 2 weeks now. And lo and behold! a video!

  • @comedyman4896
    @comedyman4896 3 місяці тому

    Whenever I get frustrated with coding, I just watch this series and I regain my wonder for coding

  • @dandreani
    @dandreani 4 місяці тому

    also, what a banger of a video... i had chills when the serpinski triangle showed up

  • @rafaelskiarteportfolio1098
    @rafaelskiarteportfolio1098 4 місяці тому

    you are an AMAZING teacher

  • @professorpro9400
    @professorpro9400 2 місяці тому

    My mind is honestly blown seeing how a simple set of rules can lead to such beauty and manifest itself in the real world 😍when you compared to real life examples, that just made it. Awesome video as always, amazing teacher and very inspirational :) keep up the good work!

  • @clintongryke6887
    @clintongryke6887 4 місяці тому

    Great enthusiasm!

  • @mattbrennan7216
    @mattbrennan7216 4 місяці тому

    Fantastic!

  • @superdepressif6047
    @superdepressif6047 4 місяці тому

    I have your first edition and I had a lot of fun with it, the only critic I have is that some of the exercise don't give you much information about how to complete them which can be a little bit frustrating, but I love all the projects we get to code.

    • @TheCodingTrain
      @TheCodingTrain  4 місяці тому +1

      Maybe I can improve this for the new version!

  • @Election0747
    @Election0747 4 місяці тому

    Together with Flash Math Creativity, The Nature Of Code is my favourite book of all time. It had so much interesting stuff in there I still use often. Looking forward to the new edition.

  • @Miionu
    @Miionu 4 місяці тому

    so amazing!

  • @nothinglastsforever0000
    @nothinglastsforever0000 4 місяці тому

    Congratulations on your book publication!

  • @Rumplestiltzchen
    @Rumplestiltzchen 4 місяці тому

    That intro was clean!

  • @ColinTimmins
    @ColinTimmins 4 місяці тому

    Awsome video! Im excited for 2024. Your videos and your book will come in handy for both my path and and guide into code land. =]

  • @theprogson
    @theprogson 4 місяці тому +1

    man you some what changed my life. I mean i discoverd you when i was supossed to learn to my exam after middle school so i could go to good hischool in Wielun (its in Poland) and this was my break through in programming field i always wanted to be programmer but that was the time when i actually understood the basics concepts. Now Im 20 and Im in college on Cybersecurity faculty. I want to thank you for your work. It's trully realy good. I'd love to do something with you some project or something.

  • @ayushtripathi429
    @ayushtripathi429 4 місяці тому

    Awesome Video Dan!

  • @Mel-mu8ox
    @Mel-mu8ox 4 місяці тому

    Always inspired when I get homework from Coding Train :D

  • @TheCatull
    @TheCatull 4 дні тому

    Danke!

  • @shanebenlolo3160
    @shanebenlolo3160 4 місяці тому

    I’d really love a video on rendering a tile server wrapped around a sphere using a cubemap (as opposed to a equirectangular texture).
    This would require you to map all edges of each face of the cube to their respective neighbors to perform the correct query for the lat long bounds. Please consider! Love your work ❤

  • @kossboss
    @kossboss 4 місяці тому

    he is back!

  • @Byt3me21
    @Byt3me21 3 місяці тому

    Thanks that was a great video!

  • @djbolodocaco775
    @djbolodocaco775 4 місяці тому +1

    honestly these videos could be called "fall in love with code"

  • @CrashingThunder
    @CrashingThunder 4 місяці тому +4

    I'm gonna use this as an opportunity to build something different with Godot. I don't usually do stuff like this since it's primarily a game engine, but it seems like a fun way to make a nice UI and a little sandbox for exploring the various rules.

  • @williamjones5367
    @williamjones5367 3 місяці тому

    veryyyyy fking cool man, i enjoyed this thoroughly, keep it up!

  • @msclrhd
    @msclrhd 4 місяці тому +2

    It would be interesting to code Langton's Ant and more generally Turmites. You can get different ant patterns/behaviours by having two ants at different positions/
    and orientations.

  • @PotionScape
    @PotionScape 3 місяці тому

    I recently added cellular automata to my terrain generation for nicer looking caves (3d). I found this video very interesting as well

  • @unchaynd7266
    @unchaynd7266 4 місяці тому +2

    Another interesting idea would be to decide the next state of the cell by looking at some other combination of cells rather than the cell and its neighbors... for example, you could decide the cell's next state based on the 3 cells to its left or right.
    And of course, you could also look at more than just 3 cells. You could look at the cell, its 2 left-hand neighbors, and its 2 right-hand neighbors. This would yield 2^(2^5) (a little over 2 billion) possible rules.

    • @TheCodingTrain
      @TheCodingTrain  4 місяці тому

      You should try this and submit it to the passenger showcase!

  • @blendedtutorials
    @blendedtutorials 4 місяці тому

    genius as hell

  • @VanguardParty
    @VanguardParty 3 місяці тому

    Amazing

  • @richarddragon2589
    @richarddragon2589 Місяць тому

    Thanks!

  • @407wrld3
    @407wrld3 4 місяці тому

    Nice project!

  • @user-iz1dt5pm7d
    @user-iz1dt5pm7d 4 місяці тому

    Wow, I've done that week ago, but in c++. Nice to see, how it's done in other languages!

  • @YuHayate
    @YuHayate 4 місяці тому

    im whatching 4 hours after you posted the video :)

  • @filipemelo1107
    @filipemelo1107 4 місяці тому

    i remember watching your videos when I didnt know how to program... Now I work as a software engineer and just got my degree, so you are kinda of part of it too. Thanks!

  • @MahBor
    @MahBor 4 місяці тому +1

    Looking forward to more Coding challenges in 2024

  • @johngc2010
    @johngc2010 4 місяці тому

    GREAT VIDEO

  • @SpringySpring04
    @SpringySpring04 2 місяці тому

    The manual truth table from the a == 0 && b == 1 && c == 0, etc. Part actually made me go crazy lol. I'm taking a digital logic class in college and i've learned how to simplify boolean expressions using k-maps and minimization and stuff, so I was just going crazy from seeing that lol

  • @dev_zone2006
    @dev_zone2006 4 місяці тому

    Simply amazing 😊😊❤❤❤😅😅

  • @zehanimohamedyoussef3736
    @zehanimohamedyoussef3736 4 місяці тому

    Glad I watched this ✨
    Reminds me of college/uni days while we never learnt things this way👨‍🎓👨‍💻 😎🆒

  • @KiwiRedstone
    @KiwiRedstone 4 місяці тому

    9:04 You got me there, I was internally screaming why you use that if else mess instead of multiplying a, b, c, with their respective binary value then call the index 😂

    • @_miyu
      @_miyu 4 місяці тому

      Seeing the steps "the long way" is a really good way to understand whats actually happening. Recognizing "oh, there's a pattern here" and "I can simplify" is the next steps to take. It's good to show it off that way so everybody can understand.

  • @Deditzy.
    @Deditzy. 3 місяці тому

    One day I’m gonna say “kids, I watched this man go from a full head of black hair …” you got me through Uni man! Kudos!

  • @flameofthephoenix8395
    @flameofthephoenix8395 2 місяці тому

    17:56 While looking at the Sierpinski's triangle Cellular Automata, I noticed that it can be predicted, if you have a diagonal line then you just need to compute how many diagonal lines branch off of it, which is fairly simple, you can determine that every other pixel in a diagonal line will branch, moreover the length of the line that branches off follows this pattern, 010201030102010 although it is actually 2^0,2^1,2^0,2^2,2^0,2^1,2^0,2^3,2^0,2^1,2^0,2^2,2^0,2^1,2^0. Regardless, you can use this to render Sierpinski's triangles with a fair bit of efficiency. It's also worth noting that you must start with two diagonal lines in order to make the whole triangle.

  • @mpanganiban
    @mpanganiban 4 місяці тому

    Nature of Code 2 would be the perfect gift for people I'm always pushing to code 😂

  • @GrandpaGameHacker
    @GrandpaGameHacker Місяць тому

    I write a generic basic CA in C++ using bitset as birth and survival rules recently, it could simulate highlife, gol, night and day etc. without swapping algorithms. It performs worse in certain scenarios but it was general and could produce cool results with random rulesets.

  • @clavesi
    @clavesi 4 місяці тому

    LET'S GOOOOOOOO

  • @josemacalintal1915
    @josemacalintal1915 4 місяці тому

    You should try coding up the Rock-Paper-Scissors ruleset for a 2D CA setup. A three-state (or 4 depending if you include a null state) that generates stable spirals. It has been compared to the Belousov-Zhabotinsky reaction in chemistry.

  • @FunnyPeregrineFalcon-vc3il
    @FunnyPeregrineFalcon-vc3il 3 дні тому

    Just bought the book!

  • @benlenders7813
    @benlenders7813 4 місяці тому

    Just started into project Euler as an excuse to learn Python. Watching this gave me that same twinge of "hey that's neat".