Just had a 'spirited' conversation with a co-worker about the succinctness of the following BASIC statement:
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
It's the title of this book, and will simply print a sequence of /
and \
characters, alternating between the two randomly, resulting in a pattern similar to this:
(Image borrowed from http://www.flickr.com/photos/rndmcnlly/5058442151/sizes/o/in/photostream/)
Being of a PHP proclivity, we wondered what the most compact way of writing the same thing in PHP would be, and came up with this:
while(1) { echo chr(47 + 45 * rand(0,1)); }
chr(47)
is a /
character, and chr(92) is a \
. So the statement echo chr(47 + 45 * rand(0,1));
will randomly alternate between the two, ad nauseam.
In a language of your choosing, write the shortest program or function to output an infinite random sequence of \
and /
characters, where each character has an equal probability of being chosen.
{}
braces, but that's about as concise as you can make it. \$\endgroup\$for(;;)
is always shorter than awhile
\$\endgroup\$