Skip to content

Instantly share code, notes, and snippets.

@cosinekitty
Created November 7, 2019 02:03
Show Gist options
  • Save cosinekitty/4c6a84f40077886cc1dcfd2de8445e14 to your computer and use it in GitHub Desktop.
Save cosinekitty/4c6a84f40077886cc1dcfd2de8445e14 to your computer and use it in GitHub Desktop.
Program to translate raw quine template into working quine source code.
#!/usr/bin/env python3
with open('raw.c', 'rt') as infile:
raw = infile.read()
data = [('1' if c=='$' else str(ord(c))) for c in raw]
delim = raw.index('$')
quine = raw[:delim] + '{' + ','.join(data) + ',0}' + raw[delim+1:]
with open('quine.c', 'wt') as outfile:
outfile.write(quine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment