6 ms·
A single line of Basic sends readers into a labyrinth
- alexleavitt 14y agoHighly recommend picking up this book. As a former local colleague of Nick Montfort, I can say it's going to be a great read.
- ynniv 14y agoI recently read Racing the Beam (Monfort, Bogost), a survey of the defining technical details of the Atari 2600. I've read a number of gaming history books, and RtB was by far the most interesting. It might be better described as a hacker history of the platform, focusing on the limitations of the system and the hacks around them that caused Atari VCS games to have a personality distinct from its contemporaries. Also highly recommended. [http://www.nickm.com/vcs/ http://www.nickm.com/vcs/] [http://www.platformstudies.com/ http://www.platformstudies.com/]
- joeld42 14y agoI remember learning this trick, not sure where I learned it from but this particular snippet had a huge impact on me. I spent hours and hours playing with variations on this.
- zaptheimpaler 14y agoThe article seems to be a a lot of hyperbole without much substance. The code itself is simple. CHR$(205.5 + RND(1)) becomes CHR$(205) or CHR$(206) depending on the random number. 205 generates a \ , and 206 generates a /.
- mmphosis 14y ago10 PRINT MID$("/\",1.5+RND(1),1);:GOTO 10 Run it on another old-school computer, like an Apple II, and you won’t get the same transfixing result, for details that have to do with the Commodore 64’s character set, called PETSCII.
- akkartik 14y agoIs it the same as this C snippet? main() { while (1) printf("%c", rand()%2 ? '/' : '\\'); } Edit: Golfed my original snippet down, then put back original after mmphosis's identical translation.
- mmphosis 14y agoyes. #include <stdio.h> main() { for(;;) printf(rand()%2 ? "/" : "\\"); }
- activepeanut 14y agoSmall variant: void main() { while (1) printf("%c", "/\\"[rand()%2] ); }
- zem 14y agoi think the key point is that / and \ do not span their character cells from corner to corner.
- oelmekki 14y agoI quite thought the same thing. Ok, it's fun, but writing a lengthy article like this for that ... Wait, a book ?
- diego 14y agoCan this book not be available in digital form? Amazon and MIT Press only list the hardcover edition. http://mitpress.mit.edu/books/10-print-chr2055rnd1-goto-10-0 http://mitpress.mit.edu/books/10-print-chr2055rnd1-goto-10-0
- superprime 14y agoThe article links to the book's (free) download page: http://10print.org http://10print.org
- keithpeter 14y agoI'm downloading it now. Would like to donate by buying but UK Amazon site lists it as out of stock.
- diego 14y agoThanks, I wonder who is the idiot who downvotes an honest question. Still, I would pay $9.99 for mobi or epub. PDF is inconvenient for the Kindle and the iPad. Converting with Calibre is a chore, and rarely yields good results.
- cubicle67 14y agoI find GoodReader excellent for pdfs on the iPad. It's not only a great reader but also allows annotation etc plus makes getting pdfs into and out of your iPad fairly painless
- xefer 14y agoI've always had a soft spot for mazes. Seeing how a recursive function could solve a maze was what got me hooked on programmng to begin with. At the time it was mind-blowing. It was the first time that software seemed like magic.
- LarryMade 14y agoIf you were like me back in the 80s on a PET you did that and then moved up to more complex randomness with other graphic symbols like the four corner curves or bends. I think they had that line in one issue of Creative Computing with a bunch of other character graphic effect snippets.
- akavi 14y agoA version that works in bash: yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash Source and credit: http://stackoverflow.com/a/13612327 http://stackoverflow.com/a/13612327
- masak 14y agoPerl 6, using Rakudo: perl6 -e 'loop { print <9585 9586>.roll.chr }' In fact, perl6 -e 'loop { print <╱ ╲>.roll }' will work too if your terminal is set up properly.
- deleted 14y ago[deleted]
- akkartik 14y agoBeautiful: http://i.imgur.com/tsFR9.png http://i.imgur.com/tsFR9.png I can't believe I've programmed for 15 years without knowing about this.
- halter73 14y agoPowerShell for those on Windows: for (;;) { write-host -n (get-random ╱,╲) } Obviously this requires a font supporting those characters. MS Mincho seems to serve well: http://www.microsoft.com/typography/fonts/font.aspx?FMID=206 http://www.microsoft.com/typography/fonts/font.aspx?FMID=206
- ygra 14y agoYou can also just use for(){...}. No need for the semicolons there.
- cocoflunchy 14y agoIf you don't want to install a font, you can use slashes. Works pretty well. for (;;) { write-host -n (get-random /,\) } It's kind of nice with _ and | too : for (;;) { write-host -n (get-random '_','|') }
- diego 14y agoRuby: echo 'loop do print ["\u2571","\u2572"].sample end'|ruby
- anigbrowl 14y agoI spent many long hours playing with this on a Vic-20 back in the 80s. Commodore BASIC was so weird that you pretty much had to hack it.
- rwg 14y agoIf you have a machine with a UTF-8 terminal and a recent-ish Perl (tested on Perl 5.10 + Mac OS X 10.6), you can play along at home by running: perl -e '$ |= 1; binmode(STDOUT, ":utf8"); while (1) { print chr(9585.5 + rand()); select(undef, undef, undef, 0.01); }'
- ComputerGuru 14y agoThis was the most beautiful one for me: http://cl.ly/image/3y0I2J2q421E http://cl.ly/image/3y0I2J2q421E
- DanBC 14y agoThat gives me a gentle optical illusion - there's a sort of 3d effect going on and I can't tell which way is up or out or in or down.
- SoftwareMaven 14y agoWhile interesting, it isn't the same. I'm not sure what, exactly, the difference is, but I don't get the feeling of "labyrinth". Instead, I get the feeling of a bunch of similar glyphs.
- vacri 14y agoTry changing the 0.01 at the end to 0.001 or lower.
- rossjudson 14y agoJust to be clear...it doesn't generate a labyrinth. It generates something that looks like a labyrinth, but isn't one. It's just random forward and backward slashes.
- akkartik 14y agoThe device you're on doesn't generate text. It looks like text, but it's really just red, green and blue dots.
- hideo 14y agoI presume OP means that it may not have a 'solution'. i.e. i can't really navigate it like a 'proper' labyrinth.
- derleth 14y ago> The device you're on doesn't generate text. It looks like text, but it's really just red, green and blue dots. Printers don't generate text. It looks like text, but it's really just ink on paper. The point is that real labyrinths have properties these pseudo-labyrinths don't. To be specific: > In colloquial English, labyrinth is generally synonymous with maze, but many contemporary scholars observe a distinction between the two: maze refers to a complex branching (multicursal) puzzle with choices of path and direction; while a single-path (unicursal) labyrinth has only a single, non-branching path, which leads to the center. A labyrinth in this sense has an unambiguous route to the center and back and is not designed to be difficult to navigate. http://en.wikipedia.org/wiki/Labyrinth http://en.wikipedia.org/wiki/Labyrinth
- sp332 14y ago"In colloquial English, labyrinth is generally synonymous with maze" means that yes, this is a labyrinth because "labyrinth" is synonymous with "maze". "Many contemporary scholars observe a distinction between the two" means "most people don't observe any distinction between the two."
- mjn 14y ago
- anthonyb 14y agoPython version: python -c 'import random; print "".join(random.choice(r"/\\") for i in range(80*24))'
- groovy2shoes 14y agoSame thing, but with corner-to-corner unicode glyphs: python -c 'import random; print "".join(random.choice([u"\u2571",u"\u2572"]) for i in range(80*24))'
- est 14y agopython -c "print ''.join(__import__('random').choice(u'\u2571\u2572') for i in range(80*24))"
- jonmrodriguez 14y agoAnother fun example of a computer generating mezmerizingly complex art from simple code is that as a kid, I wrote a Langton's Ant implementation in QBASIC on a DOS machine (don't remember the version). IIRC this was using Graphics Mode 1 (320 x 200 pixel framebuffer), and I used PSET and PRESET to draw white and black pixels. This so far sounds ordinary but: The cool thing was that I forgot to write the bounds check to make sure the ant stayed inside the framebuffer! So the ant would happily trundle off-screen, encounter arbitrary bits that were in that memory, and would often eventually return back on the screen from a different location. Or sometimes (probably due to encountering zeros offscreen) it would run a lap around the edge of the screen and then veer back inward. Langton's Ant: http://en.wikipedia.org/wiki/Langtons_ant http://en.wikipedia.org/wiki/Langtons_ant
- asdfs 14y agoReminds me of this blog post about a Tron game that didn't check memory bounds either: http://blog.danielwellman.com/2008/10/real-life-tron-on-an-apple-iigs.html http://blog.danielwellman.com/2008/10/real-life-tron-on-an-a...
- chengsun 14y agoI had the same bug (no pun intended), but in JavaScript. It does produce some interesting effects after making a few laps. http://chengsun.github.com/walk.html http://chengsun.github.com/walk.html I still am a "kid", and it amuses me that I'm making the same stuff on modern platforms that have already been done on DOS machines by kids like me.
- jonmrodriguez 14y agoAwesome!! Glad you were able to reproduce the effect! :D
- teeja 14y agoSame fascination with this, I think, as with the simple rules of Conway's. S'pose there are other such "a-mazing" simple revelations still floating in the void?
- pom 14y agoReading this right now. I also made an SVG version at http://romulusetrem.us/10print/ http://romulusetrem.us/10print/
- javajosh 14y agoJavaScript (in a browser): var r = 0; function go(){setTimeout('document.write(r++ % 80 ? Math.round(Math.random()) ? "\\\\" : "/" : "<br>"); go()', 100)}; go(); This was actually a lot more difficult for me to write than I thought it would be. `document.write` blocks and also a browser doesn't wrap by default, hence the r variable. This will, of course, nuke any page you happen to run it on. :) P.S. Why is code formatted so badly on HN these days? Until that's fixed I'll just use normal formatting.
- javajosh 14y agoThe node version is also hard to write. I tried `process.stdout.write` but it always prints a newline, at least from the repl.
- fragsworth 14y agoIt may be somewhat interesting to analyze the properties of randomly-generated labyrinths of this type. For instance, some spaces are clearly enclosed. i.e., there is a finite border outside which you cannot escape. Some paths seem to run on for a very long time. Are all paths enclosed? If so, given a random point on a randomly generated maze, what is the average area of an enclosure?
- rfugger 14y agoI don't think a "corridor" ever forks, so it's not really a labyrinth where there are decisions to be made about which way to go, it's just a bunch of disjoint long, twisty hallways.
- iliis 14y agoAdd a space every now an then and it becomes a 'real' maze: #include <stdio.h> main() { for(;;) {printf(rand()%2 ? "╱":"╲"); if(rand()%100<1) putchar(' ');} }
- dubya 14y agoMathematicians have given this some thought. The relevant keyword seems to be "Truchet tilings", though there's a curved variation that's more widely known. Here's a very accessible overview with some lovely generalizations of this pattern: http://mypages.iit.edu/~krawczyk/rjkisama11.pdf http://mypages.iit.edu/~krawczyk/rjkisama11.pdf
- dnm 14y agoa place to run the code http://codeazur.com.br/stuff/fc64_final/ http://codeazur.com.br/stuff/fc64_final/
- mjcohenw 14y agoI discovered this on my Commodore PET probably about 1980 and presented it at a users' group meeting (in the Los Angeles area). I have no way to prove this right now, but I swear that this is true.
- keithohara 14y agoprocessing.js version: http://studio.sketchpad.cc/sp/pad/view/dWrYcgtqBO/rev.2 http://studio.sketchpad.cc/sp/pad/view/dWrYcgtqBO/rev.2
- dwoldrich 14y agoThat's cool! If you don't have a C64, you can input a similar line of code at https://clubcompy.com/?shell https://clubcompy.com/?shell 10 PRINT TOCHAR 13.5 + RANDOM; GOTO 10 RUN I prefer the hopelessly lost maze variant! :> 10 PRINT TOCHAR 222.5 + RANDOM; GOTO 10 RUN
- itry 14y agoPHP: while (1) echo rand (0,1) ? "╱" : "╲";
- itry 14y agoYou can execute it on the command line like this: php -r 'while (1) echo rand (0,1) ? "╱" : "╲";'
- p4bl0 14y agoRacket version (should work in most Scheme implementation too actually): (let loop () (display (list-ref '("╱" "╲") (random 2))) (loop)) Use `racket -e <expr>` tu run it directly, for Guile it should work with `guile -c <expr>` but it seems that the unicode charaters make it crash (however it works if you copy the line of code in Guile's REPL rather than on the command line with -c).
- taylorbuley 14y agoThe PDF is free: http://trope-tank.mit.edu/10_PRINT_121114.pdf http://trope-tank.mit.edu/10_PRINT_121114.pdf via http://lab.softwarestudies.com/2012/11/10-print-book-from-mit-software-studies.html http://lab.softwarestudies.com/2012/11/10-print-book-from-mi...
- herbig 14y agoYou kids and your fancy one liners: import java.util.Random; public class Maze { public static void main(String[] args) { String[] blah = new String[] { "╱", "╲" }; Random rng = new Random(); for (;;) { System.out.print(blah[rng.nextInt(2)]); } } }
- huseyinkilic 14y ago13 bytes version in 6502 machine code: 7C 00 20 D2 FF A1 85 29 01 E9 92 D0 F5 (Save this as a .prg file and run it in your favourite C64 emulator or on the real thing itself. Please note that the first two bytes are actually required by .prg file format to indicate load address. The actual code is 11 bytes). For more information: http://pouet.net/prod.php?which=60810 http://pouet.net/prod.php?which=60810