Hacker Newsnew | comments | show | ask | jobs | submitlogin
akavi 589 days ago | link | parent

A version that works in bash:

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

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

akkartik 589 days ago | link

Beautiful: http://i.imgur.com/tsFR9.png

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


halter73 589 days ago | link

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


cocoflunchy 589 days ago | link

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 '_','|') }


ygra 589 days ago | link

You can also just use for(){...}. No need for the semicolons there.


1337p337 589 days ago | link

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 +}}'


lloeki 589 days ago | link

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

    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?


anonymous 588 days ago | link

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


lifthrasiir 589 days ago | link

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


dalke 589 days ago | link

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 ';'.


ionelm 588 days ago | link

You can write it like this:

    python -c "while 1:import sys,random;sys.stdout.write(random.choice('\/'))"
and it's shorter too !


diego 589 days ago | link


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


diego 589 days ago | link

This makes it slower, so it's more pleasant to watch:

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


inkel 589 days ago | link

Why piping to ruby? You have the -e operator for that:

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


petercooper 589 days ago | link

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'


inkel 589 days ago | link

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


SoftwareMaven 589 days ago | link

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.


JonnieCache 589 days ago | link

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.


SoftwareMaven 589 days ago | link

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


nlh 589 days ago | link

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 :)


Scaevolus 589 days ago | link

A slight modification to make it generate mostly solvable mazes: `yes 'c=(┻ ┫);printf ${c[RANDOM%2]}'|bash`


anthonyb 589 days ago | link

choosing from

  || __     # (2 pipes, one space, 2 bars)
seems to work pretty well, too


masak 589 days ago | link

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.


rsiqueira 589 days ago | link

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


itry 589 days ago | link

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:


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.


guiambros 589 days ago | link

> ...not as elegant as the BASIC version

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


billysilly 589 days ago | link

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


vmind 589 days ago | link

(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))


kelseyhigham 587 days ago | link

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}


aolol 588 days ago | link

Watch it character-by-character in bash:

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


teeja 589 days ago | link

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


pavel_lishin 589 days ago | link

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


jjjeffrey 589 days ago | link

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


yakiv 589 days ago | link

Was it maybe trouble with '\' being treated as an escape character?


Guidelines | FAQ | Lists | Bookmarklet | DMCA | News News | Bugs and Feature Requests | Y Combinator | Apply | Library | Contact