3 ms·
This is shorter for starters: print(bin(0x443214c74254b635cf84653a56d7c675be77df)[2:]) May be possible to shave off a few bytes with f'..' strings, or see i
by arp242 3y ago
This is shorter for starters:
print(bin(0x443214c74254b635cf84653a56d7c675be77df)[2:])
May be possible to shave off a few bytes with f'..' strings, or see if there are any repeating patterns, I'm not the sort who enjoys "code golfing", but "use base-16 to represent a base-2 number more compactly" seems fairly obvious to me.
- jabowery 3y agoWrong output. What you call "code golf" is the essence of the natural sciences: Inducing natural laws from the data generated by those natural laws. In this case, the universe to be modeled was generated by: print(‘’.join([f’{xint:0{5}b}’ for xint in range(32)]))
- arp242 3y agoOh right, you need the leading zeroes won't get printed; need a formatting string with a specific width for that. I don't do much Python so I don't recall the exact syntax off-hand, but the point was: there is an obvious way to compact the number that can be done without any analysis of the number itself (or even looking at it, for that matter). While print(literal) is "cheating" if you ask for "create a program that generates ...", it is a very obvious thing to do if you want to go down that route.