Created
November 7, 2019 02:03
-
-
Save cosinekitty/4c6a84f40077886cc1dcfd2de8445e14 to your computer and use it in GitHub Desktop.
Program to translate raw quine template into working quine source code.
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
#!/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