How Does a Single Line of BASIC Make an Intricate Maze? 438
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.
Enterprise Java Version (Score:5, Funny)
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 );
}
}
Yes Captain (Score:2, Funny)
that's what our sensors are picking up.
Re:Sad day for slashdot... (Score:5, Funny)
Re: Without the use of a loop!? (Score:4, Funny)
Pratt by name . . .
Re:Tricks with Slash and Backslash (Score:4, Funny)
perl -e 'while (1) { print rand() > .5 ? "/" : "\\" }';
Quick, claim it doesn't have a loop and write a book. :)
Re:Really? (Score:2, Funny)
It's a step up from the plastic on Mars story a few days ago.
Re:Without the use of a loop!? (Score:5, Funny)
The code puts out random positive space objects while the mind sees a single, complex negative space.
Sadly, that's the way I'm seeing slashdot these days...
Re:Without the use of a loop!? (Score:5, Funny)
Maybe he's trolling to see who will admit that they know BASIC.
Diablo (Score:4, Funny)
Wow. Who would have known that the code for Diablo is so simple.
Re:Without the use of a loop!? (Score:5, Funny)
Much like a televangelist or politician then.
Re:Without the use of a loop!? (Score:5, Funny)
The code puts out random positive space objects while the mind sees a single, complex negative space.
I don't even see the random positive space objects anymore. I just see blonde, brunette, redhead...
Re:Enterprise Java Version (Score:4, Funny)
Perl version: Search CPAN, someone's bound to have written a maze module.
Re:Record breaking (Score:4, Funny)
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.