Skip to content

Instantly share code, notes, and snippets.

@dhepper
Created December 2, 2017 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhepper/9d89768e4b68337bff49b5cda14eb2e8 to your computer and use it in GitHub Desktop.
Save dhepper/9d89768e4b68337bff49b5cda14eb2e8 to your computer and use it in GitHub Desktop.
Script to generate code for Coffee Machine Machine code golf
# 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