Maze Solving - Computerphile

Поділитися
Вставка
  • Опубліковано 25 гру 2024

КОМЕНТАРІ • 993

  • @MattMcConaha
    @MattMcConaha 7 років тому +866

    This guy is my favorite on the Computerphile channel. I think that the algorithms he talks about are the most interesting to me, and I've even coincidentally researched a lot of them on my own before seeing his videos. There are some other interesting algorithms for maze solving that I would recommend looking into if you are interested in this video.

    •  7 років тому +9

      which other interesting algorithms? i really like them

    • @LucaDiCarlo-LDC
      @LucaDiCarlo-LDC 7 років тому +5

      Is there one where you would grid the maze as he has done in the video, but you just delete all nodes with only one connection that is not beginning or end of the maze over and over until the last node of this kind ? I was wondering about this algorithm while watching the video.
      Would it be performant ?
      (he may have used that in the video and I didn't understand everything, because of my english)

    • @DatMilu2K
      @DatMilu2K 7 років тому +4

      Matt McConaha Yeah I like him too. Just after watching the Video about the "Slow Loris" attack, i implemented it myself in Delphi :D

    •  7 років тому

      do you like delphi?

    • @DatMilu2K
      @DatMilu2K 7 років тому +3

      András Gyarmati Yeah, its very efficient in coding and running speed while being a lot easier than C++ ("power of C++, convinient like C#", i code(ed) in all three) but its a little bit outdated and too expensive which results in a very small community. I use it only for GUI applications on Windows, Linux and Android as there arent any modern libraries for 3D programming and many other things aswell as not having all the C/C++ compiling options for other platforms such as Arduino.

  • @joshuasy10
    @joshuasy10 5 років тому +18

    I just noticed the at the start and the at the end, very nice

  • @mrfreezy7457
    @mrfreezy7457 6 років тому +518

    "Each of these squares is a square, and I'll hear nothing more said about that". I love the idea of a maze made out of parker squares.

    • @omikronweapon
      @omikronweapon 6 років тому +13

      Parker maze?

    • @rewrose2838
      @rewrose2838 4 роки тому +4

      That would be an amazing collab, team Parker Pound

    • @liminos
      @liminos 4 роки тому +11

      It's so awesome that all nerds (counting me in) are somehow the same kind of broken 😂😂
      I already hear my colleages, after presenting my ideas, say "We'll, why is it all made of squares?", "What's the path/obstacle ratio of the squares you generated?", "How does it behave if..", "Why haven't you implemented ...?" 😂😂😂

    • @luisa.machado6595
      @luisa.machado6595 2 роки тому

      😂😂😂

  • @Hambrack
    @Hambrack 3 роки тому +102

    Not a programmer myself, but one "improvement" I'd make is to treat every white square with 2 adjacent white squares "not a node", and make every other square a node. This because a turn is no different from a corridor. You can still only go one way.

    • @en7998
      @en7998 2 роки тому +20

      Just thought of that while watching and immediately thought that someone alse must have stumbled upon this. It becomes more apparent when you use an actual graph that doesnt use the grid, though.
      To extend on this idea, one could then use this graph and start deleting nodes with only one neighbor (that are not start or finish)

  • @KarlosSacramento
    @KarlosSacramento 7 років тому +1904

    1. open MS Paint
    2. Load maze image
    3. use "fill" tool
    4. click
    5. maze solved.

    • @baronvonbasscat
      @baronvonbasscat 7 років тому +132

      Sweet algorithm homie!

    • @proxy1035
      @proxy1035 6 років тому +194

      honestly wondering how the fill algorithm works

    • @AdoobII25
      @AdoobII25 6 років тому +188

      It's as he described his initial solution at the beginning, the fill algorithm checks around the clicked pixel for neighbour pixels of the same colour values. You can't solve a maze using MS paint all the time because the main path will be branching which will result in a root-like path, and in a very large maze it would be hard to track the solution because paths might overlap.

    • @deziograff
      @deziograff 6 років тому +145

      That would only really show the areas where the user cannot access

    • @ctbully
      @ctbully 6 років тому +113

      This is why you arent a programmer

  • @nickwoodward819
    @nickwoodward819 7 років тому +91

    love how excited Mike looks when he gets asked, or says something nerdy.
    comes across as a great guy

  • @igniteflow
    @igniteflow Рік тому +6

    Mike would simply walk right through any interview. An Effortless, engaging and fun communicator. Great stuff

  • @cerebralm
    @cerebralm 5 років тому +371

    "Each of these squares IS a square, and I'll hear nothing more said about it then that!"
    Non-Euclidean geometry I see :P

    • @garychap8384
      @garychap8384 5 років тому +10

      All MY squares have three sides - more efficient.

    • @startrek0336
      @startrek0336 5 років тому

      @@garychap8384 They're on spheres, right?

    • @garychap8384
      @garychap8384 5 років тому +1

      @@startrek0336 of course... all the best squares are! ; )

    • @vegardpig8634
      @vegardpig8634 4 роки тому

      what does that mean lol

    • @rinzhler6922
      @rinzhler6922 3 роки тому

      Yeah it is a square cause there are only four orthogonal directions of movement in maze like the 4 edges of square

  • @Sachin-at
    @Sachin-at 7 років тому +824

    I m going to kill UA-cam for not suggesting this channel to me years back

    • @AureliusR
      @AureliusR 7 років тому +11

      Have you not seen the sister channels, Numberphile, Periodic Videos, Objectivity? You're welcome.

    • @Jako1987
      @Jako1987 6 років тому +7

      "This guy seems very familiar.", "Oh yes I have subscribed to this channel."

    • @WarrenGarabrandt
      @WarrenGarabrandt 5 років тому +2

      Careful, UA-cam will demonetize your comment for language like that. :)

    • @anandsuralkar2947
      @anandsuralkar2947 5 років тому

      Dan

    • @jadenmax679
      @jadenmax679 5 років тому

      same

  • @hellterminator
    @hellterminator 7 років тому +85

    Fun fact: You can use GIMP/Photoshop to solve mazes as long as the image is simple enough. The path through the maze splits the walls into two distinct parts, so all you have to do is use the fuzzy select tool/magic wand on any of the walls, create a new layer, expand the selection by a couple pixels (so it becomes continuous and covers part of the path between the walls), fill it in with some color, shrink it by couple pixels and delete it. You'll be left with a nice clear path going through the maze.

    • @indjev99
      @indjev99 7 років тому +4

      No. You could have walls not connected to the outside walls.

    • @hellterminator
      @hellterminator 7 років тому +18

      indjev99 Alright, let me revise my previous statement: The maze is split in _at least_ two distinct parts.
      The method still works.

    • @indjev99
      @indjev99 7 років тому +2

      Yes.

    • @RustyTube
      @RustyTube 6 років тому +2

      Where’s the fun in that?

    • @omikronweapon
      @omikronweapon 6 років тому +10

      you could also just take a pencil and draw it by hand. but the point of the video is to write a program to do it, and learn/practice writing code while doing it. So why would you use photoshop?

  • @RikuJako
    @RikuJako 7 років тому +538

    *camera man gets bored*
    "So what was in tv?"
    ;)

    • @burrytellam
      @burrytellam 7 років тому +55

      Riku Jako I thought he was expecting an answer like "The Crystal Maze".

    • @Volvith
      @Volvith 7 років тому +53

      "Something that doesn't require much attention and isn't complicated..."
      So, which of the Transformer movies was it? :)

    • @josgeerink9434
      @josgeerink9434 7 років тому +1

      OOOOOH

    • @BuggSmasher
      @BuggSmasher 5 років тому

      Terminator ?

    • @eoghanbarry1432
      @eoghanbarry1432 5 років тому +2

      Mazerunner!

  • @Omnifarious0
    @Omnifarious0 7 років тому +9

    Several people mentioned parts of the idea I'm about to mention, and I thought of them too when watching the video, but I don't think anybody's combined it all.
    So, it's obvious that squares that only have two adjacent white neighbors are pointless to have as nodes. But, as you're trying to track the node representation of the maze to the maze, nodes for any bend (even a bend you'd be forced to take anyway) are very useful.
    So, build the nodes the way he originally did. Then take a pass through them all and eliminate any nodes that have two connections to their neighbors. You replace each with an edge that has the weight of the two combined edges that used to lead to and from the node you're eliminating.
    This reduces memory use and greatly reduces the number of nodes you have to consider.
    You could also eliminate all nodes that have only one edge (except start and end) completely, but then you have to go to the node you connect to and see if you just eliminated enough edges that it only has one or two and so on. By then you're basically solving your maze.

    • @Darticus42
      @Darticus42 6 років тому +1

      Eric Hopper it's much more efficient, yes, but it would probably make displaying the path difficult, since you lose info about where the corner was. Adding a separate x weight and y weight could do the trick, summing for the shortest path algorithms
      I like the idea of continuously pruning the tree of redundant nodes until you solve the maze though. I wonder if an algorithm exists for that yet (probably)

  • @youvebeensubbedto8009
    @youvebeensubbedto8009 4 роки тому +41

    12:29
    "I've got a very technical question for you."
    " :) "

  • @digivince
    @digivince 7 років тому +127

    The default windows 10 app for viewing images is really shitty for viewing small images because it blurs the image in an attempt at removing jagged edges. If you use the older windows photo viewer program, you won't get that. It's still built into W10.

    • @whuzzzup
      @whuzzzup 7 років тому +19

      Just use IrfanView.

    • @luckymouse1988
      @luckymouse1988 7 років тому

      digivince - Came here just to say this.

    • @abcdefghilihgfedcba
      @abcdefghilihgfedcba 7 років тому

      I personally use Honeyview… idk how it compares to others.

    • @RealCadde
      @RealCadde 7 років тому +13

      "shitty" depends on what you are after.
      Viewing photographs like this is better than viewing them pixelated. It's called linear or bicubic interpolation and there are videos on those subjects on this channel.
      It's actually slower to view images in that way when zooming in. Or rather, more operations takes place.
      So if you really wanna be picky about it (which i will), Windows 10's viewer is BETTER than a viewer without the feature. The only thing that's missing is a switch to turn the effect on or off.
      One more thing. All that processing for interpolation takes place on the GPU anyways. So it doesn't run much slower than without the filter.

    • @luckymouse1988
      @luckymouse1988 7 років тому +6

      You know what's also missing from the Windows 10 Photo's application? Proper levels of zoom.
      the Windows Photo Viewer is able to zoom in to a factor of 20, whereas the Photo's application is only able to zoom in to a factor of 4. Tested on a 10x10 red .png file, maximum zoom on Windows Photo Viewer yields a 200x200 red square, whereas the Photo's application yields a 40x40 red square.
      Aside from blurring things up, the Photo's application is inadequate when trying to display small images because it can't scale them past 400%.
      Unless I'm missing something, that is.

  • @trankaz
    @trankaz 7 років тому +37

    Really love the videos with Mike, he and tom scott is the reason i started watching computerphile

    • @realGBx64
      @realGBx64 6 років тому +3

      I really like Tom Scott, I am just not convinced that he really has any experties in anything he's talking about :D

  • @timothymclean
    @timothymclean 7 років тому +397

    It strikes me that the nodes at corners are kind of redundant. I'm not sure how the code implementation works, but it seems like you'd only need nodes if the pixel had three or four possible exits. Though getting it to connect would probably be tricky...
    Maybe something could be set up after the initial node-net is created that makes a pathfinding node-net and "cleans up" those nodes? I'm not sure if that would result in a net computing profit, though.

    • @SosirisTseng
      @SosirisTseng 7 років тому +51

      Probably he wants to keep the links straight for easier tracing.

    • @ten.seconds
      @ten.seconds 7 років тому +38

      It's not going to be that much slower, but if I want to get rid of this inefficiency, I would add two changes like this, then it would probably work:
      1. If the pixel has 2 connections only, flag the corner during the object creation (In programming terms: I'll have CornerNode extend Node, or maybe I'll have a nodeType variable in the object, or even have some kind of "node in construction" object)
      2. If we are trying to add a second connection to a node with the flag, the program deletes the node and merges the connection.
      (There'll be more than just 2 changes to the code (at least one more place, after a glance at the program), but the gist is these two)

    • @Kartaal
      @Kartaal 7 років тому +5

      You could check the corner nodes and push the connections to the connected nodes. So A connects to B connects to C and B is a corner node. Just say that A connects to C and C connects to A in reverse. For step count and such, you could just use the one on C, possibly with a noted direction for colouring in the path and a check for "Oh, I hit a wall and this has to be a corner, take the other exit until next node"

    • @KohuGaly
      @KohuGaly 7 років тому +2

      probably not. To remove the corner nodes you have to iterate through all nodes once, then search for the path in this collapsed array. When you pathfind through the full array you are not bound to iterate through all of the nodes, so it should take less time.

    • @nine.ties6
      @nine.ties6 7 років тому +16

      You don't need those corner nodes at all, the computer could skip diagonally to the next one, he probably left them there 'cause the solution tracing system would be a pain otherwise... Or at least that's what I thought

  • @slipperynickels
    @slipperynickels 7 років тому +1247

    Semicolons in your Python code? Blasphemy, I say.

    • @potatoonastick2239
      @potatoonastick2239 7 років тому +197

      He's probably too used to C/C++

    • @hiddencactus4855
      @hiddencactus4855 6 років тому +56

      Or Java

    • @mayube9292
      @mayube9292 6 років тому +91

      As a C#/JS/PHP programmer by trade, it took a while for me to get used to not using semicolons in python, and I still use them sometimes if I'm the only one who'll ever see the code (ie for quick scripts)

    • @serenityrahn5656
      @serenityrahn5656 6 років тому +26

      i use semicolons all the time to set variables etc... helps hold the line count down

    • @oroville12345
      @oroville12345 6 років тому +2

      Ness is that you?

  • @soupisfornoobs4081
    @soupisfornoobs4081 4 роки тому +3

    Thanks English caption author, for your humourous misinterpretations of what they were saying. Very useful for someone trying to actually use the captions to enjoy the video. All the hearing-impaired in the world are bowing down to you.

    • @Benjamin-mj1ck
      @Benjamin-mj1ck 3 роки тому

      From looking at them I would guess they were auto-generated. There are a lot of subtle mistakes which a human wouldn't make.

  • @VincentVegas64
    @VincentVegas64 3 роки тому +1

    I was given this task in school in 1980. At that time there were no graphics, we realized it with # in a text file, which had to be created manually. The task was not only to find a way, but the shortest way. The computer had an 8080 CPU or something similar. Operating system was EUMEL, programming language was ELAN, both developed in Germany.
    Later I thought things backwards and wrote a program that created mazes, since there was nothing like that before, as my teacher told me.
    Still later I developed probably the first 3D game in which you could run around in the maze and shoot a monster. You could also shoot through the walls. If you hit an outer wall, you lost. By switching to a different terminal after each move, the other people could see the player running through the maze from above - and make fun of him.
    The construction of the views was realized by loading text parts consisting of /, \ and #. Only the differences to the previous picture were loaded because the construction of a whole page with 80 x 24 characters took several seconds. By reloading only the changed parts, a fluid display was possible.

  • @adhamuhajier
    @adhamuhajier 7 років тому +474

    Maybe do a video on SHA-1and its collision attack. Its successor SHA-2, its variations etc.

    • @jpchevron
      @jpchevron 7 років тому +64

      And Tom Scott needs to do it.

    • @Falcrist
      @Falcrist 7 років тому +14

      Motion seconded.
      All in favor say "Aye".

    • @pablowestphalen
      @pablowestphalen 7 років тому +2

      Falcrist Aye

    • @MiChAeLoKGB
      @MiChAeLoKGB 7 років тому +5

      Yep, and I want him to also do the video about CloudBleed.

    • @chicken6180
      @chicken6180 7 років тому

      Goodwine I think that the topic is complicated enough where it can be 2 parts, part 1: Intro to cryptography, asymmetric encryption, what are collisions, etc. P2 when Google explains is a dumbed down version of Google's method

  • @crooksandcrafts3262
    @crooksandcrafts3262 7 років тому +2

    Yeah, this guy is the best at illustrating and explaining his concepts. I think the others make too many assumptions about the general knowledge of their viewers. That being said, I think even those who are computer scientists can enjoy these videos, which is why his approach is so refreshing.

  • @Dusk-MTG
    @Dusk-MTG 4 роки тому +6

    After a day at work spent programming, Mike Pound gets home and "feels like doing some programming in front the TV".
    Damn man, that's some real passion over here.

  • @tendividedbysix4835
    @tendividedbysix4835 6 років тому +1

    Kind of makes you marvel how the IT guys manage to get the robots to open doors and stuff, if even programming the simple tiny maze concept was this complicated. Well done computer programmer folks, you're the bomb.

  • @guitarloser07
    @guitarloser07 7 років тому +18

    I like that you didn't include the code in your video as it could distract from the logic demonstration. What you've included in this video is the most fun part of programming (problem solving). Great fun in this one!

  • @z1k1c1321
    @z1k1c1321 7 років тому +1

    Coding something simple like that and seeing the result can be the most amazing feeling.

  • @MacoveiVlad
    @MacoveiVlad 7 років тому +188

    At 14:14 i think he meant to say "2 million nodes" not "2 thousand nodes". Nice video!

    • @9999rav
      @9999rav 7 років тому +6

      Macovei Vlad I was going to write this :D

  • @x-seronis-x
    @x-seronis-x 7 років тому

    Never thought of doing a maze solver with nodes like this which makes me feel like i've overlooked such a beautiful solution for soo many years. But coming up with rules at a glance to determine if a given square needs to be a node or a path:
    S = square being analized
    A = square above S
    B = square below S
    L = square left of S
    R = square right of S
    Square state can either be Wall or Empty. Square type can be node or path
    if( A.state == B.state && L.state == R.state && A.state != L.state )
    S.type = path
    else S.type = node
    Using this criteria you never have to care what the type (node/path) of any other square is when figuring out what the current one. Because all 'paths' are straight lines with walls on each side and the above two equalities and one difference proves this. Everything else is a node.
    Now we need to make connections between nodes. While examining each node on each of its 4 sides there will either immediately be a wall, immediately be another node, or be a path that leads to a node in that straight line direction. If we have each 'connection' object record the number of square until we reach the next node then we can not only find the path through the maze, but by comparing all connections we can also find the SHORTEST path through the maze quite quickly since we only look at the nodes and not every pixel of the maze.

  • @JonSebastianF
    @JonSebastianF 6 років тому +27

    LOL... the auto-subtitles at 1:24 _"so I thought to started by coming up with some rules that my maid have to follow"_

  • @GolembladeMC
    @GolembladeMC 5 років тому +3

    This captures the essence of programming perfectly

  • @ryanlapchynski1542
    @ryanlapchynski1542 7 років тому +70

    You'd only need nodes on white spaces with more than 2 adjacent (not diagonal) white spaces. At any white space with 2 adjacent spaces, there's no decision to be made, and any with 1 adjacent space would be a dead end, and you wouldn't want to go there anyway.

    • @vonkruel
      @vonkruel 7 років тому +2

      After finding a solution it may be a bit more work to trace the path, but that seems insignificant compared to all the cache misses as "extra" nodes are traversed over & over during the search. Actually in C++ (and C) you could store a 2-bit "direction" value in the lowest-order bits of a Node* because a Node* will always be at least 4-byte aligned. The direction says which way to go (up/down/left/right) in order to reach the connected node, so when you're tracing the path after finding a solution, you start out in that direction and then take _the only possible path_ from there to reach the connected node. Makes sense to me?? I'm a bit sleep-deprived though.
      _Yeah, never mind the direction data.. Since there's 3 or 4 connected nodes, just store the pointers in order by direction. I just need the UPS guy to show up and then I can sleep._

    • @binarin
      @binarin 7 років тому +7

      Since he is drawing the result path he needs to know the positions of the corners it passed.

    • @kelpsie
      @kelpsie 7 років тому

      True, but you can store the path between nodes as part of the connection, then use that to draw the final solution. It would increase memory overhead, but decrease solve time drastically on large mazes. Granted, memory overhead is probably more important.
      Another type of node that can be removed is one with only two UNIQUE connected neighbours, like the two nodes that make up the loop on the left of the sample maze. You'd have to do a bit of intermediary pathfinding to store the shorter path, though.

    • @philrod1
      @philrod1 7 років тому +2

      He talks about Dijkstra's algorithm, so he must store edge data somewhere (cost). You could also store the physical path on the edge, too. The corner nodes are redundant when turning the maze into a weighted graph.

    • @keeyan2166
      @keeyan2166 7 років тому +1

      Binarin I don't think it does. The path can easily be recreated after solving the maze by just following the white spaces between the 2 nodes that need to be connected.

  • @suvetar
    @suvetar 3 роки тому

    Still fascinating to watch, even in 2021! Thank you Computerphilers!

  • @Toobula
    @Toobula 7 років тому +4

    Mike, here is a fun one to solve that might get your interest: Imagine a game played on a grid. Player one starts in the center cell on the left side, player two in the right center.The players move alternately, each stepping from the square they are on to an adjacent square (up, down, left, right). Each time a player enters a square, it becomes "wall" in the sense of your mazes. Very simply, play continues until a player cannot move, in which case he loses. Is there an optimal strategy? Code it. This game is similar to "Light Cycle" but in fact was implemented a coin game well before Tron. I cannot remember the name, but it also allowed diagonal moves which were traced as two moves, one in the direction last traveled, followed by one to the side. You might want to code for that rule. (A nice feature was that the 16 directional moves - eight each player - were mapped to the notes of a lovely minor mode scale, so as you played, you were making up little fugues.)

    • @HiddenLotus9
      @HiddenLotus9 7 років тому

      Toobula sounds interesting, I'll have a go

    • @boggers
      @boggers 6 років тому

      Check out the board game / mobile app Quoridor, not exactly the same as your idea (you can either move or place a wall anywhere each turn) but still a great game.

  • @DontTalkShite
    @DontTalkShite 7 років тому +107

    Brilliant practical example that implements the techniques taught in his last couple of videos. Love this guys way of teaching.

  • @waasar
    @waasar 7 років тому +4

    I really enjoy playing around with this kind of little programs. Thanks for sharing this with us.

  • @code-dredd
    @code-dredd 7 років тому +57

    Do a video on the fact that the SHA-1 cryptohashing algorithm got cracked recently by Google researchers.

  • @vertxxyz
    @vertxxyz 7 років тому +10

    I like the idea of pruning the graph when you reach a dead end (a node with 3 walls) as you create your graph.

  • @AnimilesYT
    @AnimilesYT 7 років тому +14

    15:43 almost at the start, where the red part is above the blue part it has a straight line going between them. So you're right, there is a silly little thing that could've made the path way shorter.

  • @alfredwarnsater3099
    @alfredwarnsater3099 7 років тому

    These kind of vidoes where Mike codes something and then talks about it and shares it with us are really educational and I hope to see more of this!

  • @fredwalker3765
    @fredwalker3765 7 років тому +7

    i'm currently working on a sokoban solver, you really should try it that's pretty interesting... if you're getting bored in front of your TV again, you can think about it

  • @styleisaweapon
    @styleisaweapon 5 років тому +1

    The "left turn algorithm" is best described as "Run with your left hand on the wall" - back in the early days of robotic maze solvers this was the best possible algorithm because all decisions had to be local. It is only when gobs of memory was available that the bots could build a decent model of the maze while it was solving it and thus intelligently skip areas.

  • @bamless95
    @bamless95 7 років тому +3

    I did this as an assignment the fist year of university. I didn't create an explicit graph but treated the image as an implicit graph in wich every node was a pixel. This way i didn't have the need of storing extra informations, saving a lot of memory.

  • @bluegiant13
    @bluegiant13 6 років тому

    My favourite episode on Computerphile so far!

  • @joeytje50
    @joeytje50 7 років тому +105

    please don't do the stretching of the video to "make it look better..." I'd much rather just stretch it in my head, with the original image. If you want it to be clear, use the animation, if you want to show his fingers, show a regular view like 8:48 or something. The stretched thing really makes me a bit dizzy.

    • @philiptkd1
      @philiptkd1 7 років тому +1

      joeytje50 +

    • @Sir_ClickALot
      @Sir_ClickALot 7 років тому +18

      It took a little effort to ignore the distorted hand but after I managed that I really think the 'corrected' image looked fine and helped to show what he was actually pointing at. If it's something that really does bother a lot of people then I'd suggest animating that part of the video as well, but it's a lot of extra effort and personally I like this solution. For me at least it's better than having to do a perspective transformation in my head, way more annoying.

    • @BlakeJPhoenix
      @BlakeJPhoenix 6 років тому +2

      Unnecessary nitpick

  • @marcusk7855
    @marcusk7855 5 років тому +2

    I implemented these at University(Depth. Breadth, A* search and Dijkstra's algorithm). The people that came up with them were very clever.

  • @BrutalHellfire
    @BrutalHellfire 6 років тому +5

    Great stuff Mike. But you can save some more nodes by rejection those which has exactly two open sides.
    You have given me a weekend project. Thanks 😊

  • @lulairenoroub3869
    @lulairenoroub3869 Рік тому +1

    Every time he said depth first search, I thought he was saying breakfast search, and it was completely believable to me that it was just called that, and there was some plausibly interesting anecdote about why this particular algorithm had been given the name of breakfast search, to which I was simply not yet privy.

  • @semnet3217
    @semnet3217 5 років тому +7

    3:01 ''each of this squares is a square and i will not say anything about it other than that''
    Wow

  • @7th_CAV_Trooper
    @7th_CAV_Trooper 2 роки тому +1

    "it'll take longer" and then a youtube ad kicks off. lol

  • @frankmalenfant2828
    @frankmalenfant2828 7 років тому +8

    I probably means handling more nodes but I'd find if fun to get all possible solution by recursively removing dead end nodes until there is none.

    • @9999rav
      @9999rav 7 років тому +1

      Frank Malenfant you would be left with loops

    • @spiritlevelup1036
      @spiritlevelup1036 6 років тому

      Look up pruning it is a real thing and is used to reduce memory overhead, it doesn't increase it

  • @lasseibsen2942
    @lasseibsen2942 5 років тому

    Strangely, this clip has entered the zone of "Series and episodes you put on when you just want something cozy on the 2. screen" - Must be the 10. time i watch it now

  • @benjaminbrady2385
    @benjaminbrady2385 7 років тому +3

    You'll want to make sure the end is always a node in case there are no junctions between the start and end

  • @sabriath
    @sabriath 7 років тому

    You can mark any dead-end nodes during the 1-pass algorithm in a separate list; afterward, you can go through this list and prune off all nodes connected to it that don't have multiple choices. This will reduce the amount of work for the search algorithm. What's neat about that is if multiple dead ends meet at an intersection, it doesn't matter what order they are pruned, the entire intersection will be reduced as well (in the 8x8 grid in the video, the entire bottom left part of the maze is cleared).

  • @Hyuts
    @Hyuts 6 років тому +8

    4:28 lol that editing though.

  • @redbaron3555
    @redbaron3555 3 роки тому

    Unbelievable how much I like to listen to Dr. Mike Pound, super interesting and funny and so easy to understand. Thank you!!

  • @ScrapMek
    @ScrapMek 7 років тому +4

    I can't wait to write my own! This is inspiring.

  • @yngve1993
    @yngve1993 7 років тому

    You mentioned python not being quick, but have you tested out cython? Profile your code, find bottlenecks, write that in cython, have it translated into C, compile and import it into python as if it was python code. Absolutely amazing!

  • @benoitb.3679
    @benoitb.3679 5 років тому +12

    "One of the cool things about being able to program is, if you think 'ooh, I wonder if I can write something that will solve mazes?', you can then immediately go and do that."
    Truer words, never.

    • @Rx7man
      @Rx7man 4 роки тому +1

      It's really interesting to find the "gotchas" in what seems to be a simple problem to solve, and then find ways to work around them

  • @axelBr1
    @axelBr1 4 роки тому +1

    Just came across this channel; can't believe that, that printer paper is still available!

  • @Pfaeff
    @Pfaeff 7 років тому +80

    Why not use a proper image viewing program?

  • @chadestioco
    @chadestioco 7 років тому +1

    Incidentally, I am currently studying Jump Point Search. Got a bit excited when he mentioned making a graph out of the grid based on corridors as it is similar to one of the basic ideas behind JPS. Shame he did not go fully in to that.

  • @TheScabbage
    @TheScabbage 7 років тому +19

    You'll get 8 times more pixels if you stored it as a byte array instead of a boolean array, and used the individual bits.

    • @Ludix147
      @Ludix147 7 років тому +1

      Scabbage does a single boolean value take up a whole byte?

    • @pH7oslo
      @pH7oslo 7 років тому

      Depends on the programming language, and then it's often implementation-defined (it's usually either 1 or 4 bytes in c/c++ for instance).
      AFAIK, in Python it's a sub-class of integer, which uses 24(!) bytes for its representation. However, given that there are only two possible boolean values, you use pointers to a static instance of either true or false. Which takes up either 4 or 8 bytes of memory, for 32bit and 64bit respectively (the platform-specific size of a pointer).
      There are ways to get Python to store bools as bytes, or even in bit-maps, but unless you're actively taking advantage of these representations chances are it will just slow down your code.

    • @TheScabbage
      @TheScabbage 7 років тому +5

      +Ludix147 The smallest addressable memory size on modern hardware is one byte, unless you're working with some incredibly small, unconventional and basic hardware.
      Typically no one worries about it in most cases because memory capacity per dollar has gotten so large, but if he's having memory issues it'd be better to store all his bits in a byte array and use bit masks to address individual bits (at the cost of a small performance hit like +pH7oslo said) instead.

    • @hellterminator
      @hellterminator 7 років тому +1

      +pH7oslo Actually in C/C++ bool is a typecast of char, so it is 1 byte (of course depending on aligning on stack or in structures, the following 1 to 7 bytes might be unused). If you make an array of bools, it will be 1 byte per bool, _however_ vector has a template specialization for bool that actually uses a bitfield, so you only use 1 bit per bool.

    • @AureliusR
      @AureliusR 7 років тому +1

      Yes, but in C it's also very easy to specify the number of bits you want a variable to use.

  • @antonw6455
    @antonw6455 7 років тому

    This is a great way to get people to start thinking about the difficulties of searching! You may want to revisit how the problem was solved by introducing the limitation of visibility. Specifically, as an individual at the start, you can't see the entire maze at one time, you can only see and gather information about the immediately adjacent corridors. Maybe a problem for extra credit?

    • @Ghorda9
      @Ghorda9 7 років тому

      Look up A* (A star)

  • @imveryangryitsnotbutter
    @imveryangryitsnotbutter 7 років тому +4

    What if you made an algorithm that tries to solve the maze beginning from the entrance and exit simultaneously?
    In one step, it tests a node from the entrance path, and in the next step, it tests a node from the exit path, and it continues alternating in this way until the two paths meet in the middle somewhere. Also, each time the algorithm deduces that a node is definitely on the correct path, it updates the destination node for the other path. So the two paths are not each searching for their corresponding entrances, but rather each aiming for the head of the other path.
    This would be useful in a maze with a start and exit at the top, connected by a very long U-path that touches the bottom. Initially the pathfinding will stumble as they try to cut directly sideways, but as the heads of the confirmed paths move ever downward, they'll start aiming towards the bottom more and more, where they'll eventually meet and complete the solution.

    • @the_brutal_king4314
      @the_brutal_king4314 6 років тому

      This is a viable solution, but requires more memory. You also have to check when both sides have met.

  • @Eikenhorst
    @Eikenhorst 2 роки тому

    I like the algorithm for turning the grid into a graph. I would probably do another few passes to remove nodes on this graph that have only 1 or 2 edges connecting to that node. If it has only 1 edge connected (and not start or end) it is a death end, so remove. If it has only 2 edges, it can be removed as there is no decision to be made at this node. This graph simplification can be done extremely fast and hugely simplifies the graph

  • @BIGWUNuvDbunch
    @BIGWUNuvDbunch 7 років тому +77

    Delete all nodes with only 2 connections

    • @iAmTheSquidThing
      @iAmTheSquidThing 7 років тому +5

      You have to add weights to the connections then though. Because you're trying to find the shortest path.

    • @BIGWUNuvDbunch
      @BIGWUNuvDbunch 7 років тому +18

      nodes with only 2 connections are equivalent to a connection: i.e. you only have one choice of where to go

    • @joshuamckinney2281
      @joshuamckinney2281 6 років тому +8

      Yeah but then it would be harder to color the maze after the fact with the path you would have to undo your deletions

    • @Djorgal
      @Djorgal 6 років тому +3

      @@joshuamckinney2281 Yeah. Why not? Keep the initial graph with all the connections in memory, solve the maze using the simplified graph then map the solution onto the first graph to, then, draw it.

    • @joshuamckinney2281
      @joshuamckinney2281 6 років тому

      @@Djorgal sure that would work. I guess you would just have to run it to see which tactic would save the most memory so that bigger mazes could be solved

  • @soccer7901
    @soccer7901 7 років тому

    This is epic, Dr. Mike always has fun stuff to present.

  • @petarmilic9729
    @petarmilic9729 7 років тому +4

    clearing deadend nodes would save memory but increase time i presume?

  • @eatbolt42
    @eatbolt42 7 років тому

    This guy is easily the best presenter.

  • @philrod1
    @philrod1 7 років тому +9

    This was OK, but *generating* mazes is *way* more fun. I know, because I did it. I wrote three different maze generation algorithms (should have been 4, but I never did get Eller's algorithm to work) and a bunch of solvers (A* being best, naturally). The rules for a perfect maze are that there must be one, and only one, path between any two points in the maze (using the same up, down, left, right grid system as i the video). I'm actually tempted to make a video about it myself; I already have the code, and it is animated so you can watch it work.

    • @serenityrahn5656
      @serenityrahn5656 6 років тому +2

      if you already have the code and the animation, you should upload and show/teach us!

  • @ethanarrowood7454
    @ethanarrowood7454 7 років тому

    I found my new favorite channel on youtube.

  • @Nickgowans
    @Nickgowans 7 років тому +16

    as someone who's programming ability includes "hello world" and cnc machine centre programming, most of this video was "blablablablablablablablablabla" but I did find it incredibly fascinating :)

    • @Rx7man
      @Rx7man 4 роки тому +1

      I really ought to learn g code, but my lathe and milling machine are both digitally controlled in the older sense of the word.. Controlled with MY digits!

  • @FBuilding
    @FBuilding 7 років тому

    I don't know why but this thumbnail just does it for me 👑

  • @atrumluminarium
    @atrumluminarium 7 років тому +17

    So we have algorithms that solve mazes... What about algorithms that create them? By create I mean the output should be solvable (preferably uniquely).

    • @Theasstasticvillain
      @Theasstasticvillain 7 років тому +10

      I think he used a program to output those huge ones, I doubt he made a 6k by 6k pixel maze :S

    • @atrumluminarium
      @atrumluminarium 7 років тому

      Eli Tzar It would be nice if they show it some time

    • @moilui1664
      @moilui1664 6 років тому +4

      that's the only thing i was thinking about during this video, thanks for not making me feel alone lol

    • @atrumluminarium
      @atrumluminarium 6 років тому

      Moi Lui you're welcome :D

    • @T0ly113
      @T0ly113 6 років тому +3

      Look up maze generation algorithms on Wikipedia. There's at least one really simple one to recreate and maybe learn a thing or two!

  • @stevensexton5801
    @stevensexton5801 7 років тому +1

    Your library is missing 'The C Programming Language' by Brian W. Kernighan and 'Code Complete: A Practical Handbook of Software Construction' by Steve McConnell

  • @Booskop.
    @Booskop. 7 років тому +18

    Nice ghostcube!

  • @pedropicapiedra3598
    @pedropicapiedra3598 4 роки тому +1

    Many time ago I readed you can solve most mazes with the right hand trick. When you enter the maze you put your right hand in the wall and you keep it in the wall until you find the exit.

  • @bpark10001
    @bpark10001 7 років тому +11

    What happens to your algorithm is a corridor is more then 1 pixel wide? Say there was a 50 x 50 white square in the middle of the maze?

    • @9999rav
      @9999rav 7 років тому +16

      Brian Park it would probably create new node on every pixel

  • @samtukua4508
    @samtukua4508 6 років тому

    I am so happy to know that the programmer I look up to chose, of all the programming interfaces, the same sublime text that I use.

  • @jeffreyblack666
    @jeffreyblack666 6 років тому +5

    The first maze you used wasn't a perfect maze. It had 3 possible solutions, 1 of which is shorter than the other 2 which are equal.
    Is there a reason you didn't simplify the nodes further (even as an intermediate structure) where if a node is just connected to 2 other nodes you remove it and link those 2 nodes directly; rather than just doing that when the nodes are collinear? That simplification could also remove nodes which only connect to one other node, and it could all be done in the first simplification if it keeps track of connections rather than just making them.
    Also, if you are using nodes, you aren't finding the shortest path but the "simplest". A simple example of that would be a maze where you enter top left and exit bottom left. The simplest path could be a loop around the outside, while the shortest could be a zigzag along the left 2 columns.

  • @rabidbigdog
    @rabidbigdog 6 років тому +1

    When I was a lad (ha!) we used to use Z80s with 1KB ram and a wheeled maze robot, mine were made of Mecano and have competitions in a built box maze.

  • @PongoXBongo
    @PongoXBongo 7 років тому +5

    Climb the wall, and walk on top of the walls to the nearest edge. ;)

  • @koz_iorus1954
    @koz_iorus1954 4 роки тому +1

    I really like that the animations are slightly in 3D

  • @Droobilicious
    @Droobilicious 7 років тому +11

    Nodes with only only 2 connections should be eliminated for the solution calculation

  • @CattleRustlerOCN
    @CattleRustlerOCN 5 років тому

    At 12:37 my question would be why is there no real-time graphical representation running on screen for this. I might try this in Javascript using real 2d objects and collision for the player object to feel and figure its way out based on it knowing where its been and being able to back track its way out of dead ends

  • @kevnar
    @kevnar 7 років тому +3

    I once coded a maze in PERL that was a million squares by a million, and then I got the algorithm to solve it. It found the exit. The only trouble was, the maze was so big, I had to just take the program's word for it. I couldn't actually display it on screen. I knew it worked, though because I began with a 10x10 maze and drew it in ascii characters, with the solution. But when I upped it to 1,000,000 x 1,000,000, I just had to turn the drawing function off.

    • @beanthemachine3675
      @beanthemachine3675 6 років тому +1

      You know that even if each square is just 1 byte, a maze that big would take up an entire terabyte of memory? I'm curious how you supposedly went about handling that

    • @iIiWARHEADiIi
      @iIiWARHEADiIi 6 років тому +1

      @@beanthemachine3675 most probaly vector lines. They contain start and end points only

  • @theperson101ful
    @theperson101ful 7 років тому

    Mike Pound is my favorite on Computerphile! Keep up the awesome videos :)

  • @RobertT1999
    @RobertT1999 7 років тому +7

    I love this channel. Being an A level Computer Science student, just looking at the title allowed me to know that this video was about algorithm searching. Personally, I would create a boolean data type 2D array with the X and Y indexes being the same as the X and Y pixels of the image. I would scan each pixel of the image and if the pixel was white, it would assign true to the index in the array that is the same as the pixel position. That is probably the only thing I would do differently but I haven't actually thought about the rest of it. Too busy revising for my Computer Science PPEs next week.

    • @gasquakestudios
      @gasquakestudios 7 років тому +7

      Robert Tucker - (shadykillar123) What was the point of this comment? Haha

    • @RobertT1999
      @RobertT1999 7 років тому +3

      I just thought someone might have a little interest in what I was saying but I guess I was wrong.

    • @gasquakestudios
      @gasquakestudios 7 років тому

      Robert Tucker - (shadykillar123) It's cool dude, if I'm being honest I'm just a little "salty" over not being in college yet to have more time to do what I love.

    • @RobertT1999
      @RobertT1999 7 років тому

      +gasquakee That's weird. I actually read your comment thinking that you didn't like to read that I was studying something you wanted to. Don't worry, I understand why you feel like this. When you are in college, it'll be great. Just think, you will be enjoying yourself doing something that I won't be doing in a few months time because I will have finished A level by then. I wish I could go back to the same position you are in and do it all over again. I hope whatever the reason for you not being in college goes away soon so you can actually do what you love.

    • @gasquakestudios
      @gasquakestudios 7 років тому

      Robert Tucker - (shadykillar123) Finishing highschool is the barrier! So how was your experience of college; do you feel you're leaving with a better mind?

  • @tomchitling
    @tomchitling 7 років тому

    You could mark all Black walls connected to the outside-wall on the Left of the start finish as "red". Mark all those walls connected to the right wall as "Green", and any walls on central islands as other colours. Then Block off all white squares between two of the same colour as these are dead ends. What you have left is ALL your possible paths.

  • @MazeFrame
    @MazeFrame 7 років тому +127

    You rang?
    Not that I actually solve mazes, just the name.

  • @aNaGrMa
    @aNaGrMa 7 років тому

    Great video. And amazing to find a comment section spewing with constructive criticism instead of hate.

  • @Nyhilo
    @Nyhilo 7 років тому +3

    Looks like he codes in SublimeText :)

  • @douglasmennella4525
    @douglasmennella4525 Рік тому

    One optimization is to run a second pass over the graph removing nodes which only have two edges connected to them since they're not actual choice points. A third pass could remove multiple edges between the same two nodes (and/or don't add them in the first place.)

  • @hanneshauptmann
    @hanneshauptmann 7 років тому +10

    420 views. nice.

    • @442277100
      @442277100 7 років тому +1

      Hannes Hauptmann nice meme

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

    I play a game where I needed to solve a max maze size of 12x12 cells but to explore the nodes, you have to actually move to them so I didn't have the luxury of just relying on code jumps to do a breadth first search, A * or any any algo that sequentially expand nodes between possible potential depths/paths. I settled on a depth first search because... well it's the easiest to code when you physically have to move through a maze and minimized the travel distance thus time to solve.
    For those that don't follow, in any sort of flood fill style algorithm such as A * or breadth first(even with a weighted graph to a lesser extent) for mazes you have to physically traverse to check the node, you end up with an n**(length of path)-1? movement for every possible path up to the shortest path distance through the maze if we're talking breadth first search, less for A * because A * won't check each potential path to it's depth upto the point it finds the exit/goal in one of the paths.
    Make no mistake, everything Dr. Mike has said in the video about the algorithms is true, if you're solving a maze programmatically(which he clearly states). Things only change if you have to physically traverse the maze to do them.

  • @dyld921
    @dyld921 7 років тому +3

    Dr. Pound is seriously attractive. I wonder if he's ever had any sexual innuendos made about his name.

  • @boggers
    @boggers 6 років тому

    You can solve perfect mazes like those generated by daedalus very easily using photoshop or similar - no code required.
    Flood fill the black walls from one corner green. Half the walls will still be black. Next, flood fill the black part red. If there is only one path, all the walls will now be either red or green. Use a maximise filter to thicken the red and green walls by 1 pixel. Where they overlap it creates a yellow line which is the solution. Remove the red and green and you're done. In photoshop specifically, you can use selection tools instead of flood fills and automate the whole thing down to a single button press which completes in a fraction of a second even on extremely large mazes.
    It works because in "perfect" mazes the walls are always bisected from entry to exit by the correct path.
    For mazes where there is more than one path, there will still be one or more islands of black in the middle after the second fill. You can continue to fill in the black areas with either red or green until there is no black remaining before running the maximise filter.
    You can use the same method with different parameters for flood fill tolerance and maximise radius to solve any maze. (eg one photographed out of a book)

  • @gchinmayvarma9030
    @gchinmayvarma9030 5 років тому +4

    Wtf just use the paint bucket tool

  • @pmarreck
    @pmarreck 7 років тому

    Just drop a virtual breadcrumb on any coordinate you step on (increment that array location by 1). When deciding where to go, pick the path with the fewest breadcrumbs (and the first one if there are more than one). Simple, solves the maze every time.

  • @TheCandoRailfan
    @TheCandoRailfan 7 років тому

    This video inspired me to make a program in the BASIC language QB64, where you can create mazes using text (either manually or by the computer) save them, and have the computer solve them. It doesn't do the quickest possible route, unless it does by luck or there's only 1 route, it just wanders randomly, never repeating the same spot twice, and when there are no possible moves, it will go to previous curves or intersections until there is a move. My code probably isn't great, and probably could be better, but it works. The maximum size is 80 * 55, including edge.

  • @thiyagutenysen8058
    @thiyagutenysen8058 2 місяці тому +1

    What does he mean by doing infront of tv