24
6
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 alternative between the two, ad nauseum.
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.
1You can lose the
{}
braces, but that's about as concise as you can make it. – Michael – 2012-12-07T16:23:46.517This is cool. What font can be used to get a similar image? – daniero – 2012-12-09T19:24:58.340
1This (picture) reminds me of the first "program" I ever wrote on my commodore 64 straight out of the manual :) ah happy days – Dale – 2013-04-09T13:31:12.160
@daniero I think the actual typeface is called Terminal, but I found it online as "Windows Command Prompt" https://codepen.io/nickforddesign/pen/WMqQdM?editors=0110
– nickford – 2018-03-05T20:49:10.183What a strange coincidence that this Code Golf repo on Github happens to have the exact same challenge... https://github.com/noops-challenge/golfbot
– Geza Kerecsenyi – 2019-07-20T18:51:30.343