Sister blog of Physicists of the Caribbean in which I babble about non-astronomy stuff, because everyone needs a hobby

Friday, 1 June 2018

The simplest code to generate a maze ?

Amazing [pun not intended, sorry] that something coherent can be generated through such absurdly simple, random code...


Originally shared by Norbert Landsteiner

I Declare Maze Day
Many amazing maze programs have been written for computers of all bread and kind, but, for some reason, there's no international Maze Day (while a few educational institutions in the US do have one of their own).

Here's one example, a quite famous BASIC one-liner for Commodore 8-bit computers generating a maze from just two characters ("\" and "/"):

10 PRINT CHR$(205.5+RND(1));: GOTO 10

Try it online: http://www.masswerk.at/pet/?run=maze

What may be a suitable date for Maze Day?
Do you remember any maze algorithms in particular?


6 comments:

  1. Python:

    import random, sys
    while True: sys.stdout.write(random.choice(u"╱╲"))

    Python3:

    import random
    while True: print(random.choice(u"╱╲"), end='')

    Other characters that work well
    fileformat.info - Unicode Characters in the Box Drawing Block

    ReplyDelete
  2. The code doesn't guarantee a solution path through the maze.

    ReplyDelete
  3. That's debatable. Generate a large enough maze and select a small enough area and you'll definitely have something with a navigable route. What it doesn't do is guarantee a solution within a fixed area.

    ReplyDelete
  4. I thought that font looked familiar...

    ReplyDelete
  5. I guess that depends on what one takes the entrance and exit definition to be. Left to right edges?

    ReplyDelete

Due to a small but consistent influx of spam, comments will now be checked before publishing. Only egregious spam/illegal/racist crap will be disapproved, everything else will be published.

Navigating the AI Hype And Hysterics

Back in the days when AI development meant working towards something like an artificial human, I had three rules to bear in mind when readi...