Live data from Hacker News

A single line of Basic sends readers into a labyrinth

slate.com

51–60 of 91 posts

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

#51

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…

Reminds 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-a...

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

#52
post #15

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

This was the most beautiful one for me: http://cl.ly/image/3y0I2J2q421E

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

#53
post #24
post #20

Earlier quoted context omitted.

Ruby: echo 'loop do print ["\u2571","\u2572"].sample end'|ruby

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.

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

#54
post #15

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

While 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.

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

#55
post #15

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

While 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.

Try changing the 0.01 at the end to 0.001 or lower.

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

#56
post #27

Earlier quoted context omitted.

Not for me. "syntax error near unexpected token ';' == no printf

It worked for me when I copied it, not when I tried retyping it. I think the fancy unicode ╱ ╲ matters vs. plain ascii \/

ascii works for me if I escape the \, ie: / \\

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

#57

Python version: python -c 'import random; print "".join(random.choice(r"/\\") for i in range(80*24))'

Same 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))'

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

#58

It 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?

I 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.

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

#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 while ';' is the statement separator python barfs on "import foo; while (True): pass". Bug or spec?

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

#60
post #10

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

After reading the article, I was really hoping the comments would be full of ports, glad to see this thread! Here's a version for the Inferno shell, because I couldn't resist:

wm/sh -c 'load std mpexpr;while{}{unicode -t ${expr 2571 1 rand +}}'

Post reply on HN