News for hackers. Stuff that matters.
Re:A single line of Basic sends readers into a labyrinth by akavi on Friday November 30, 2012 @08:31PM (#4856461)
A version that works in bash:

yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash

Source and credit: http://stackoverflow.com/a/13612327

Re:A single line of Basic sends readers into a labyrinth by akkartik on Friday November 30, 2012 @08:47PM (#4856499)
Beautiful: http://i.imgur.com/tsFR9.png

I can't believe I've programmed for 15 years without knowing about this.

Re:A single line of Basic sends readers into a labyrinth by halter73 on Friday November 30, 2012 @09:24PM (#4856578)
PowerShell 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

Re:A single line of Basic sends readers into a labyrinth by cocoflunchy on Saturday December 01, 2012 @04:30PM (#4859072)
If 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 '_','|') }
Re:A single line of Basic sends readers into a labyrinth by ygra on Saturday December 01, 2012 @08:08AM (#4857524)
You can also just use for(){...}. No need for the semicolons there.
Re:A single line of Basic sends readers into a labyrinth by 1337p337 on Saturday December 01, 2012 @03:33AM (#4857144)
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 +}}'

Re:A single line of Basic sends readers into a labyrinth by lloeki on Saturday December 01, 2012 @03:08AM (#4857124)
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 by anonymous on Saturday December 01, 2012 @06:03PM (#4859341)
I did it with

    python3 -c "`echo -e 'import time\nwhile True:\n print(u"\u2571\u2572"[int(time.time() * 100)%2],end="")\n time.sleep(0.001)'`"
The neat thing about it is that the randomness comes from the inexactness of time.sleep
Re:A single line of Basic sends readers into a labyrinth by ionelm on Saturday December 01, 2012 @08:14PM (#4859677)
You can write it like this:

    python -c "while 1:import sys,random;sys.stdout.write(random.choice('\/'))"
and it's shorter too !
Re:A single line of Basic sends readers into a labyrinth by lifthrasiir on Saturday December 01, 2012 @05:22AM (#4857298)
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 by dalke on Saturday December 01, 2012 @06:11AM (#4857373)
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 by diego on Friday November 30, 2012 @09:27PM (#4856586)
Ruby:

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

Re:A single line of Basic sends readers into a labyrinth by diego on Friday November 30, 2012 @09:29PM (#4856595)
This makes it slower, so it's more pleasant to watch:

echo 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end'|ruby

Re:A single line of Basic sends readers into a labyrinth by inkel on Friday November 30, 2012 @09:44PM (#4856639)
Why piping to ruby? You have the -e operator for that:

    ruby -e 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end'
Re:A single line of Basic sends readers into a labyrinth by petercooper on Friday November 30, 2012 @10:17PM (#4856705)
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'
Re:A single line of Basic sends readers into a labyrinth by inkel on Saturday December 01, 2012 @04:45AM (#4857246)
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 by SoftwareMaven on Saturday December 01, 2012 @01:33AM (#4857029)
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 by JonnieCache on Saturday December 01, 2012 @06:37AM (#4857405)
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.

Re:A single line of Basic sends readers into a labyrinth by SoftwareMaven on Saturday December 01, 2012 @12:47PM (#4858351)
While it was far better (and thanks for the pointer to Cathode!), I figured out what the problems are. First (and probably most important), the lines being output don't touch each other, so there are horizontal gaps across the entire screen. Second, the glyphs are much thinner, reducing the feeling of "wall".
Re:A single line of Basic sends readers into a labyrinth by nlh on Saturday December 01, 2012 @10:30AM (#4857860)
What a totally clever app. And extremely well done. Thanks for sharing! Brought joy to this not-so-old-but-old-enough child of the 80s :)
Re:A single line of Basic sends readers into a labyrinth by Scaevolus on Friday November 30, 2012 @09:28PM (#4856589)
A slight modification to make it generate mostly solvable mazes: `yes 'c=(┻ ┫);printf ${c[RANDOM%2]}'|bash`
Re:A single line of Basic sends readers into a labyrinth by anthonyb on Friday November 30, 2012 @09:34PM (#4856614)
choosing from

  || __     # (2 pipes, one space, 2 bars)
seems to work pretty well, too
Re:A single line of Basic sends readers into a labyrinth by masak on Saturday December 01, 2012 @09:31AM (#4857695)
Perl 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.

Re:A single line of Basic sends readers into a labyrinth by rsiqueira on Friday November 30, 2012 @09:54PM (#4856660)
Interactive JavaScript version: http://js.do/samples/labyrinth
Re:A single line of Basic sends readers into a labyrinth by itry on Saturday December 01, 2012 @04:22AM (#4857209)
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 by guiambros on Saturday December 01, 2012 @10:41AM (#4857902)
> ...not as elegant as the BASIC version

Beautiful statement. So much unintentional irony, and at the same time so very true in this context.

Re:A single line of Basic sends readers into a labyrinth by billysilly on Saturday December 01, 2012 @06:48AM (#4857418)
I won't claim this is elegant, but here's the same thing in one line:

for(i=1;i<300;i++) document.write(i % 30 == 0 ? "<br>" : (Math.random()>0.5) ? '\u2571' : '\u2572');

Re:A single line of Basic sends readers into a labyrinth by vmind on Saturday December 01, 2012 @12:53PM (#4858371)
(function draw(i){ return function () { document.write(i%30==0 ? '<br>' : Math.random()>0.5?'\u2571':'\u2572'); setTimeout(draw(i+1), 100) } }(1)())

A throttled run-forever version.

edit, slightly neater:

(function draw(i){ setTimeout(function (){ document.write(i%30==0 ? '<br>' : Math.random()>0.5 ? '\u2571':'\u2572'); draw(i+1); }, 100) }(1))

Re:A single line of Basic sends readers into a labyrinth by kelseyhigham on Sunday December 02, 2012 @05:44PM (#4862880)
Here's a JavaScript version without the linebreaks (it uses zero-width spaces instead): http://tinkerbin.com/uEvgxZ6g

JS: for(i=0;i<1000;i++) document.write(['\u2571\u200B', '\u2572\u200B'][(Math.floor((Math.random()*2)))])

CSS: body {line-height: 1}

Re:A single line of Basic sends readers into a labyrinth by aolol on Saturday December 01, 2012 @05:52PM (#4859306)
Watch it character-by-character in bash:

while true; do c=(╱ ╲);printf ${c[RANDOM%2]}; sleep .0001; done

Re:A single line of Basic sends readers into a labyrinth by teeja on Friday November 30, 2012 @09:39PM (#4856627)
Not for me. "syntax error near unexpected token ';' == no printf
Re:A single line of Basic sends readers into a labyrinth by pavel_lishin on Friday November 30, 2012 @10:16PM (#4856703)
It worked for me when I copied it, not when I tried retyping it. I think the fancy unicode ╱ ╲ matters vs. plain ascii \/
Re:A single line of Basic sends readers into a labyrinth by jjjeffrey on Saturday December 01, 2012 @02:22AM (#4857074)
ascii works for me if I escape the \, ie: / \\
Re:A single line of Basic sends readers into a labyrinth by yakiv on Friday November 30, 2012 @11:05PM (#4856797)
Was it maybe trouble with '\' being treated as an escape character?