python3 -c 'import random, time, itertools; any(time.sleep(0.01) or print(random.choice("\u2571\u2572"), end="", flush=True) for x in itertools.repeat(None))'
python3 -c 'import random, time, itertools; any(time.sleep(0.01) or print(random.choice("\u2571\u2572"), end="", flush=True) for x in itertools.repeat(None))'
https://github.com/the-real-tokai/macuahuitl/blob/master/tem...
(how about this fancy version with SVG output? :D No longer a single line though.)
Quite a few bytes can be golfed out of that still:
My reasoning including most failures:Whitespace is mostly trivial and not worth mentioning, except that the space between "or" and "print" can be eliminated by moving the `time.sleep` to before a string literal. Alternatively, using `!=` works almost anywhere (though not with some alternative ideas), or `;` with the `while` version.
There are several shorter ways to get an infinite loop:
The loop itself: I looked into alternatives to calling sleep at all, but computers are too fast (and variable in speed) nowadays. `os.sync` looked promising but is only slow the first time. Trying to pass its return value as an argument also failed.`flush=1` is shorter than `flush=True`. Otherwise ... I tried `sys.stdout` but hardly anything was even close:
Random: