2 ms·
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
by joshu 1y ago
10 PRINT CHR$(205.5+RND(1)); : GOTO 10
- WantonQuantum 1y agoI used to do this on my VIC-20 a million years ago. Just looking at this line brought back the visual image like it was yesterday.
- teddyh 1y agopython3 -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))'
- binaryturtle 1y agohttps://github.com/the-real-tokai/macuahuitl/blob/master/temo.md 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.)
- o11c 1y agoQuite a few bytes can be golfed out of that still: python3 -c 'while I := __import__: I("time").sleep(0.01); print(I("random").choice("\u2571\u2572"), end="", flush=1)' 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: itertools.repeat(None) # for reference itertools.repeat(0) itertools.count() iter(lambda: 0, 1) # also removes the import, so 10 chars shorter iter(''.upper, 1) # same length when spaces removed, shorter if not removed iter(int.mro, 1) # spooky, but one char shorter still range(9**99) # much longer than the age of the universe range(9**9) # 44 days # but it turns out we can skip it entirely The loop itself: any(expr for x in it) # theoretically prevents the memory leak [expr for x in it] # wastes 800 bytes per sec, 69 MB/day, 1 GB per 14 days while 1: expr # breaks one-liner unless longer `__import__("")` is used, but worth it since it eliminates the entire iterable, even before doing I=__import__ while I := __import__: # 2 chars shorter than doing the assignment inside the loop 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: any(time.sleep(0.01) or print(random.choice("\u2571\u2572"), end="", flush=True) for it) any(time.sleep(0.01) or print(random.choice("\u2571\u2572"), end="", flush=1) for it) sys.stdout.writelines(time.sleep(0.1) or random.choice("\u2571\u2572")+"\0"*8191 for it) # can avoid the flush by filling the buffer manually, but requires several more chars to import sys as well Random: random.choice("\u2571\u2572") # UTF-8 b"\xe2\x95\xb1" doesn't seem useful chr(9585+random.randrange(2)) # sigh chr(9585+(random.random()<.5)) # nope chr(9585+(os.getrandom(1)[0]&1)) # + has tigher precedence than & # that last would save 1 byte with normal `import` (since the identifier is repeated), but loses with `__import__` # is there a way to eliminate parens? Is >> or | or - useful? What about *splat?