# The One-Line Maze Program in MATLAB

A classic one-line program for the Commodore 64 microcomputer is

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

This is essentially what was printed in the section “Random Graphics” of the Commodore 64 User’s Guide (1982). The program prints a random maze that gradually builds up on-screen. The following video demonstrates it

I recently came across a 309-page book by Montfort et al. (MIT Press, 2013) dedicated to discussing this program from every conceivable angle. The book, which can be freely downloaded in PDF form, has as its title the program itself and was written by a team of ten authors with backgrounds in digital media, art, literature, and computer science. I found the book an interesting read, not least for the memories it brought back of my days programming the Commodore PET and Commodore 64 machines in the early 1980s (discussed in this post about the Commodore PET and this post about the Commodore 64). I suspect that never has so much been written about a single line of code!

Various translations of the program into other languages have been done, but I could not find a MATLAB version. Here, then, is my MATLAB offering, which takes advantage of the MATLAB `char` function’s ability to produce Unicode characters:

```while 1, fprintf('%s\n',char(rand(1,80)+9585.5)); pause(.2), end
```

The `pause` command is not necessary but helps to slow the printing down, and the argument of `pause` may need adjusting for your computer.

Are there other interesting MATLAB one-liners? This one is from Mike Croucher:

```x=[-2:.001:2]; plot(x,(sqrt(cos(x)).*cos(200*x)+sqrt(abs(x))-0.7).*(4-x.*x).^0.01)
```

And here is one to compute the Mandelbrot set, condensed from the code `mandel` in MATLAB Guide:

```[x,y]=ndgrid(-1.5:5e-3:1.5); c=x+1i*y; z=c; for k=1:50, z=z.^2+c; end, contourf(x,y,abs(z)<1e6)
```

If you know any other good one-liners please put them in the comment box below.