There is a somewhat famous Commodore 64 program that created random mazes onscreen with a single line of BASIC code. The program accomplished this by randomly printing the slash "/" and backslash "\" characters, making a surprisingly accurate display of a maze. I was wondering if this could be done with a single line of CircuitPython code, so I set out to see if it was possible (spoiler alert: It can with a caveat).
Here is the one line of BASIC code for the Commodore 64 that produces random mazes:
10 PRINT CHR$(205.5 + RND(1)); : GOTO 10
This minimal program randomly prints either the slash "/" or the backslash character "\" and repeats the process in an infinite loop. The result looks like this:
The key to the successful illusion of a maze with this technique was the font used. The C64 font had some unique features that made the illusion work: the slash and backslash characters were at a 45 degree angle, making for perpendicular corners. Also, there were no gaps between characters, either horizontally or vertically, which fully enclosed the maze walls.
Next, I needed a one line program to generate the maze in CircuitPython. With a bit of tweaking of the C64 program, I came up with this:
import random; while True:print(chr(47+random.randint(0,1)*45),end="");
Finally, I needed to use a similar font for CircuitPython (no gaps). With CircuitPython's extensive font support, you would think this would be an open and shut case. However, remember we are looking for a one line solution. Adding fonts, other than the built-in terminal font, requires several additional lines of code.
So what about the built-in terminal font? Unfortunately, the built-in font for the Adafruit Fruit Jam (the board I was using) does not have the slash and backslash characters at 45 degrees and the spacing between characters (particularly the vertical spacing) is significant.
So what was my next option? Why, try another terminal emulator! I have used the Putty terminal emulator (https://putty.software) for years accessing servers, why not try it here? Perhaps it has the right font we need for this program.
Looking at the available fonts in putty, I found this font with these display settings that fit the bill:
- Font: Terminal
- Style:Bold
- Size:12 pt (other sizes should work too)
The font settings are defined in Putty's Window->Appearance screen.
So, with the one line of CircuitPython code and using the terminal font in Putty, I was able to create this random maze:
There is a bit of a vertical gap with this font but it was acceptable for me.
So, in summary, yes, you can write one line of CircuitPython code to create random maze, provided you are using a terminal program with the right type of font.
If you like mazes, you may like other maze programs I have written (which took considerably more than one line of code to write). The maze screen saver is part of a bundle of screen savers I wrote for the Adafruit Fruit Jam and Fruit Jam OS. That project was inspired by my epaper maze maker project written for Arduino.
This page (Can You Write a One Line CircuitPython Program to Create a Maze?) was last updated on February 24, 2026.