How Does a Single Line of BASIC Make an Intricate Maze?
JameskPratt writes "This Slate article talks about a single line of code — 10 PRINT CHR$ (205.5 + RND (1)); : GOTO 10 — and how it manages to create a complicated maze without the use of a loop, variables and without very complicated syntax." Now that amazing snippet of code is the basis of a book, and the book is freely downloadable.
What is
10 something: GOTO 10
if not an (endless) loop?
...when the summary does not know what a loop is.
No editors with programming experience perhaps.
The basic definition of a loop is a GOTO to a previous address! All the rest is syntax and optimisation.
It's very cool the way this code draws a maze, but there's obviously a loop there.
(And it's “without” not “with out”, and “complicated” not “complicate”.)
That....is.....a loop.......
create a complicated maze with out the use of a loop
1. This is not necessarily a maze. It's noise. At best.
2. It's "without", not "with out"
3. There is a loop
0x or or snor perron?!
Re: "it manages to create a complicated maze with out the use of a loop"
We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
package enterprise;
/**
/**
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Collections;
import java.util.Map.Entry;
import java.util.Random;
import java.util.SortedMap;
import java.util.TreeMap;
public class Maze {
private final WallFactory<Double> wallFactory;
private final EntropyGenerator entropyGenerator;
public Maze( WallFactory<Double> wallFactory, EntropyGenerator entropyGenerator ) {
this.wallFactory = wallFactory;
this.entropyGenerator = entropyGenerator;
}
public void visit( MazeVisitor visitor ) throws MazeException {
while( true ) {
MazeWall wall = wallFactory.createMazeWall( entropyGenerator.getNewEntropyValue() );
wall.visit( visitor );
}
}
public interface MazeWall {
* @param visitor
* @throws IOException
*/
void visit( MazeVisitor visitor ) throws MazeException;
}
public static class LeftDiagonalWall implements MazeWall {
@Override
public void visit( MazeVisitor visitor ) throws MazeException {
visitor.visit( this );
}
}
public static class RightDiagonalWall implements MazeWall {
@Override
public void visit( MazeVisitor visitor ) throws MazeException {
visitor.visit( this );
}
}
public interface MazeVisitor {
void visit( LeftDiagonalWall leftDiagonalWall ) throws MazeException;
void visit( RightDiagonalWall rightDiagonalWall ) throws MazeException;
}
public interface WallFactory<T> {
* @param value
* @return the MazeWall
* @throws MazeException
*/
MazeWall createMazeWall( T value ) throws MazeException;
}
public static class StrategyWallFactory<T> implements WallFactory<T> {
private WallRepartitionStrategy<T> wallRepartitionStrategy;
public StrategyWallFactory( WallRepartitionStrategy<T> wallRepartitionStrategy ) {
this.wallRepartitionStrategy = wallRepartitionStrategy;
}
@Override
public MazeWall createMazeWall( T value ) throws MazeException {
Class<? extends MazeWall> wallClassForValue = wallRepartitionStrategy.getWallClassForValue( value );
try {
return wallClassForValue.newInstance();
} catch( InstantiationException | IllegalAccessException e ) {
throw new MazeException( "Cannot create MazeWall instance", e );
}
}
Things you think are in the Constitution, but are not.
How does this not use a loop?
Don't have a Commodore Basic interpreter? this Perl 1-liner will do the same thing:
print ["/","\\"]->[rand(2)] while 1;
It has no start or end point, and for two arbitrary points you can't guarantee that a path exists.
Frontpage slashdot story with a 10 GOTO 10 and saying it's not a loop?
Dudes, just what the fuck. I ask you that.
This article fails in English and fails in the content. Booya.
It's just randomly printing forward and backward slashes, which line up because of the font. It's nifty, but hardly amazing.
And in fact, it appears Slashdot ran an article on this a decade ago when it was called DataGlyphs.
/., in collaboration with the Erowid Vault. brings you "get high and watch this code run." Wow, it's so cool.
Sent from my ENIAC
that's what our sensors are picking up.
I remember doing that in 1980something on the PET (maybe not that line, but the logic was the same). IIRC it was a type-in along with a bunch of other cheap BASIC graphics routines in a Creative Computing - later I'm sure it showed up in RUN or Transactor for the VIC/64.
It was cool for maybe a couple hours... along with thoughts of what games could I use it with (that's how we developed game ideas old-school style, starting with cool little snippets like this.)
"Enjoy what you're doing! If it becomes drudgery, you're doing it wrong!" - Jim Butterfield
when there's a perl module for that:
http://search.cpan.org/~jgamble/Games-Maze-1.08/lib/Games/Maze.pm
"The problem with socialism is eventually you run out of other people's money" - Thatcher.
From page 4 of the book:
In short, this is not a programming book, but it appears to be a book of cultural anthropology about programming. Or perhaps a meditation which starts with one simple starting point and branching out in many different directions. Criticizing the program "10 PRINT" as trivial rather misses the point, I should think.
perl -e 'while (1) { print rand() > .5 ? "/" : "\\" }';
Quick, claim it doesn't have a loop and write a book. :)
It certainly has the intricate path part down, but most people would take issue with a "maze" that lacks a beginning, end, or any guarantee that you can get from point A to B even if you consider obvious closed loops out of bounds.
--- Most topics have many sides worth arguing, allow me to take one opposite you.
strings /dev/urandom|tr -dc '/\'
God, root, what is difference ?
Wow. Who would have known that the code for Diablo is so simple.
It eventually fills up the galaxy with ascii chars and the world ends.
When all you have is a hammer, every problem starts to look like a thumb.
This type of thing has a pretty honourable history. Back in the day, there was actually a (small?) subculture of enthusiasts who experimented with one-line or two-line basic programs (I'm sure this was the case with other platforms/languages as well). Similar to the whole demogroup scene I guess - a way of experimenting and showing off. Each line number of a basic program was limited to I think 256 characters. It could have as many statements (separated by colons) as desired. Some folks would go so far as to 'poke' machine code instructions and then jmp/execute that machine code, but I think that was frowned upon a bit as that seemed a bit like cheating... :) There were contests and so on, and popular magazines like 'Nibble' would regularly publish these mini-programs which thousands of us would type into our computers. In doing so many of us became fascinated by what was possible, even if it promoted a rather unhealthy obfuscated code style...
Naturally today with almost unlimited computing resources available to every programmer, this isn't amazing at all. But back then, this sort of thing _was_ pretty amazing - even if this isn't a particularly shining example of it. Some folks were able to generate real, playable games, or amazing visual animation effects in less than 500 bytes of source. It makes me want to drag out the old Apple II emulator and play around! Man, I wish I hadn't sold that old doorstop apple II... :)
Don't judge me based on my high slashdot user id!
int main(){for(;;)putchar("\\/"[rand()%2]);}
The book is worth reading, it retells many things from the beginning of personal computing, exploring subjects along the way. the 10 PRINT one-liner is the motivation but not the topic.
Cheers.
If you need help with the code, here's a simple explanation:
The RND(1) function will return a floating point value between 0 and 1 (technically, this is 0 to 0.999... but let's just call it 0 to 1). So the part of the code that says 205.5 + RND(1) simply returns a value somewhere between 205.5 and 206.5. Assuming the RND(1) function is a good random number generator, that means half of the numbers will be between 205.5 and 205.9999..., and half will be between 206.0 and 206.5.
The CHR$() function pulls a single character from the Commodore 64's PETSCII table. The address is always an integeter, so if you ask for CHR$(205.999), that's the same as CHR$(205). Similarly, asking for CHR$(206.5) is the same as CHR$(206).
In the PETSCII table, character 205 is a single backslash, and character 206 is a single forward slash. So what the code is doing is very simple: it simply prints either a forward slash or a backslash, and keeps doing it because it loops back to itself.
This same code won't work on Linux or Windows/DOS because in the ASCII table, the forward slash is 057, and the backslash is 134. For ASCII systems, you'd need to (basically) flip a coin and print "\" if heads, and "/" if tails.
And that's all it does. There's no magic. No guarantee it is even a solvable maze. It just looks pretty.
-jh
Here you go:
http://peter.sorotokin.com/maze/Maze.html
It's just below the java applet.
Required reading for internet skeptics
It seems as if every single user on Slashdot felt they had to chime in to alert the world that 10 GOTO 10 is in fact a loop, as if everybody else hadn't already made that point.
The thing is, GOTO 10 is a loop. Therefore it's not without a loop. QED.