Created
December 2, 2017 16:34
-
-
Save dhepper/9d89768e4b68337bff49b5cda14eb2e8 to your computer and use it in GitHub Desktop.
Script to generate code for Coffee Machine Machine code golf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to generate code for Coffee Machine Machine code golf | |
# https://codegolf.stackexchange.com/questions/149585/coffee-machine-machine | |
cm = """________._________ | |
| | \ - / | |
| || | \ - / | |
| || |___\___/ | |
| || | X | |
| | ___ | |
| | / - \\ | |
|______| / - \\ | |
| ____ | /_______\\ | |
||7:30||__________ | |
||____| | | |
|_________________|""" | |
print(len(cm)) | |
chars = list(sorted(set(cm))) | |
chars.insert(0, 'X') | |
as_number = 0 | |
for i in reversed(cm): | |
as_number *= len(chars) | |
as_number += chars.index(i) | |
alphabet = [chr(i) for i in range(32, 124)] | |
l = as_number | |
n = len(alphabet) | |
b91 = '' | |
while l>0: | |
b91 = alphabet[l%n] + b91 | |
l //= n | |
code = """b=0;c={} | |
for i in {}: b=b*92+ord(i)-32 | |
while b: print(c[b%14],end='');b//=14""".format(repr("".join(chars)), repr(b91)) | |
print(code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment