6 ms·
A version that works in bash: yes 'c=(╱ ╲);printf ${c[RANDOM%2]}'|bash Source and credit: http://stackoverflow.com/a/13612327 http://stackoverflow.com/a/13612
by akavi 14y ago
A 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
- diego 14y agoThis makes it slower, so it's more pleasant to watch: echo 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end'|ruby
- inkel 14y agoWhy piping to ruby? You have the -e operator for that: ruby -e 'loop do print ["\u2571","\u2572"].sample ; sleep 0.001 end'
- petercooper 14y agoI 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 14y agoAmazing! I always forget about the `something while other_thing` syntax, thank you for reminding me of it :)
- SoftwareMaven 14y agoI 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 14y agoTry this: http://www.secretgeometry.com/apps/cathode/ 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.
- Scaevolus 14y agoA slight modification to make it generate mostly solvable mazes: `yes 'c=(┻ ┫);printf ${c[RANDOM%2]}'|bash`
- anthonyb 14y agochoosing from || __ # (2 pipes, one space, 2 bars) seems to work pretty well, too
- teeja 14y agoNot for me. "syntax error near unexpected token ';' == no printf
- pavel_lishin 14y agoIt worked for me when I copied it, not when I tried retyping it. I think the fancy unicode ╱ ╲ matters vs. plain ascii \/
- jjjeffrey 14y agoascii works for me if I escape the \, ie: / \\
- yakiv 14y agoWas it maybe trouble with '\' being treated as an escape character?
- rsiqueira 14y agoInteractive JavaScript version: http://js.do/samples/labyrinth http://js.do/samples/labyrinth
- itry 14y agoHmm.. 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 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.
- billysilly 14y agoI 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 14y ago(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))
- guiambros 14y ago> ...not as elegant as the BASIC version Beautiful statement. So much unintentional irony, and at the same time so very true in this context.
- kelseyhigham 14y agoHere's a JavaScript version without the linebreaks (it uses zero-width spaces instead): http://tinkerbin.com/uEvgxZ6g 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}
- lloeki 14y agoThe 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?
- lifthrasiir 14y agoIt is a spec. Python in general prefers a statement over an expression, so the while statement does not have an expression form.
- dalke 14y agoPython 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 ';'.
- anonymous 14y agoI 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
- ionelm 14y agoYou can write it like this: python -c "while 1:import sys,random;sys.stdout.write(random.choice('\/'))" and it's shorter too !
- 1337p337 14y agoAfter 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 +}}'
- aolol 14y agoWatch it character-by-character in bash: while true; do c=(╱ ╲);printf ${c[RANDOM%2]}; sleep .0001; done