Slashdot Mirror


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.

13 of 438 comments (clear)

  1. Enterprise Java Version by Mr.+Sketch · · Score: 5, Funny

    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 );
    }
    }

    1. Re:Enterprise Java Version by Richy_T · · Score: 3, Funny

      Perl version: Search CPAN, someone's bound to have written a maze module.

  2. Yes Captain by Anonymous Coward · · Score: 2, Funny

    that's what our sensors are picking up.

  3. Re:Sad day for slashdot... by Zero__Kelvin · · Score: 5, Funny

    Worse yet is the fact that the editors don't either.

    --
    Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  4. Re: Without the use of a loop!? by Anonymous Coward · · Score: 4, Funny

    Pratt by name . . .

  5. Re:Tricks with Slash and Backslash by discord5 · · Score: 3, Funny

    perl -e 'while (1) { print rand() > .5 ? "/" : "\\" }';

    Quick, claim it doesn't have a loop and write a book. :)

  6. Re:Really? by Anonymous Coward · · Score: 2, Funny

    It's a step up from the plastic on Mars story a few days ago.

  7. Re:Without the use of a loop!? by stokessd · · 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...

  8. Re:Without the use of a loop!? by Black+Parrot · · Score: 5, Funny

    Maybe he's trolling to see who will admit that they know BASIC.

    --
    Sheesh, evil *and* a jerk. -- Jade
  9. Diablo by dmomo · · Score: 3, Funny

    Wow. Who would have known that the code for Diablo is so simple.

  10. Re:Without the use of a loop!? by MightyMartian · · Score: 4, Funny

    Much like a televangelist or politician then.

    --
    The world's burning. Moped Jesus spotted on I50. Details at 11.
  11. Re:Without the use of a loop!? by Anonymous Coward · · 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...

  12. Re:Record breaking by Psychotria · · Score: 3, 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.