Live data from Hacker News

A single line of Basic sends readers into a labyrinth

slate.com

61–70 of 91 posts

Re: A single line of Basic sends readers into a labyrinth

#61

Another 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…

I 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

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.

Re: A single line of Basic sends readers into a labyrinth

#62
post #10

A version that works in bash: yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash Source and credit: http://stackoverflow.com/a/13612327

Interactive JavaScript version: http://js.do/samples/labyrinth

Hmm.. thats not a oneliner. Which is what makes the Basic version interesting in the first place. Also it differs in that it does not run continously.

I shortened it a bit:

http://js.do/code/154

Still not as elegant as the Basic version.

This is one of the big downsides of how javascript is implemented in the browsers these days. There is no simple way to redraw the screen. You have to turn your whole program into a state machine and work with timouts just to display something.

Re: A single line of Basic sends readers into a labyrinth

#65
post #30

Earlier quoted context omitted.

Why piping to ruby? You have the -e operator for that: ruby -e 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end'

I can't resist a golf! ruby -e 'print %W{\u2571 \u2572}.sample while sleep 1e-3' (Updated: Made 3 chars shorter.) And a shorter, but cheats, version: yes|ruby -pe'$_=%W{\u2571 \u2572}.sample;sleep 1e-3' My favorite overall balance of readability and shortness though is: ruby -e 'print %w{╱ ╲}.sample while sleep 0.01'

Amazing! I always forget about the `something while other_thing` syntax, thank you for reminding me of it :)

Re: A single line of Basic sends readers into a labyrinth

#66
Racket version (should work in most Scheme implementation too actually):

    (let loop () (display (list-ref '("╱" "╲") (random 2))) (loop))
Use `racket -e ` tu run it directly, for Guile it should work with `guile -c ` 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).

Re: A single line of Basic sends readers into a labyrinth

#67
post #59
post #10

A version that works in bash: yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash Source and credit: http://stackoverflow.com/a/13612327

The one-line shell command python version ended up being surprisingly painful: echo "# -*- coding: utf-8 -*-\\nfrom random import choice\\nwhile(True):\\n print(choice(\"╱╲\"), end='')" | python3 or python3 -c 'exec("from random import choice\nwhile(True):\n print(choice(\"╱╲\"), end='"''"')")' (Oh, the fun of deeply nested quote escaping!) The exec / echo thing being required since we need multiple lines, because wh…

It is a spec. Python in general prefers a statement over an expression, so the while statement does not have an expression form.

Re: A single line of Basic sends readers into a labyrinth

#68
post #59

Earlier quoted context omitted.

The one-line shell command python version ended up being surprisingly painful: echo "# -*- coding: utf-8 -*-\\nfrom random import choice\\nwhile(True):\\n print(choice(\"╱╲\"), end='')" | python3 or python3 -c 'exec("from random import choice\nwhile(True):\n print(choice(\"╱╲\"), end='"''"')")' (Oh, the fun of deeply nested quote escaping!) The exec / echo thing being required since we need multiple lines, because wh…

It is a spec. Python in general prefers a statement over an expression, so the while statement does not have an expression form.

Python has two types of statements; "simple" statement and "compound" statements. Compound statements are those, like the if- and while-statements, which require multiple lines.

Only simple statements may be separated by a ';', not compound statements.

This is a bit different than what you wrote. For example, "x=4" is a statement, and not an expression, but "x=4;y=5;z=6" is a valid Python line because assignment is a simple statement, and multiple simple statements may be separated by a ';'.

Re: A single line of Basic sends readers into a labyrinth

#69

The 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 /.

I quite thought the same thing. Ok, it's fun, but writing a lengthy article like this for that ... Wait, a book ?

Re: A single line of Basic sends readers into a labyrinth

#70
post #24

Earlier quoted context omitted.

This makes it slower, so it's more pleasant to watch: echo 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end'|ruby

I tried to like it. I bumped up the font size to 36 points. I slowed down the loop to .01 seconds. Unfortunately, it isn't remotely the same. The C64 had magic. I miss my old C64.

Try this: http://www.secretgeometry.com/apps/cathode/

Lots of fun. Use it to make old stuff like this feel more authentic, or just run your builds in it and tell your housemates you're haxxing teh gibson.

TBH though the reason it doesn't feel the same is ultimately because you're not the person you were 20-30 years ago, whoever that was. Nothing to do with the code or its execution environment.

Post reply on HN