Live data from Hacker News

A single line of Basic sends readers into a labyrinth

slate.com

31–40 of 91 posts

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

#33
JavaScript (in a browser):

var r = 0; function go(){setTimeout('document.write(r++ % 80 ? Math.round(Math.random()) ? "\\\\" : "/" : "
"); go()', 100)}; go();

This was actually a lot more difficult for me to write than I thought it would be. `document.write` blocks and also a browser doesn't wrap by default, hence the r variable.

This will, of course, nuke any page you happen to run it on. :)

P.S. Why is code formatted so badly on HN these days? Until that's fixed I'll just use normal formatting.

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

#34
post #27
post #10

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

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 \/

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

#35
post #30
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

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'

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

#36

JavaScript (in a browser): var r = 0; function go(){setTimeout('document.write(r++ % 80 ? Math.round(Math.random()) ? "\\\\" : "/" : " "); go()', 100)}; go(); This was actually a lot more difficult for me to write than I thought it would be. `document.write` blocks and also a browser doesn't wrap by default, hence the r variable. This will, of course, nuke any page you happen to run it on. :) P.S. Why is code formatt…

The node version is also hard to write. I tried `process.stdout.write` but it always prints a newline, at least from the repl.

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

#37
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?

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

#38
post #26

Earlier quoted context omitted.

The article links to the book's (free) download page: http://10print.org

Thanks, I wonder who is the idiot who downvotes an honest question. Still, I would pay $9.99 for mobi or epub. PDF is inconvenient for the Kindle and the iPad. Converting with Calibre is a chore, and rarely yields good results.

I find GoodReader excellent for pdfs on the iPad. It's not only a great reader but also allows annotation etc plus makes getting pdfs into and out of your iPad fairly painless
Post reply on HN