Created
November 24, 2015 23:38
-
-
Save undergroundmonorail/e9d3a33c0026e6e5ec01 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
if len(sys.argv)!=2: | |
print 'Usage: golfer.py <file>' | |
exit(1) | |
filename = sys.argv[1] | |
code = [] | |
with open(filename, 'r') as f: | |
for line in f.read().splitlines(): | |
code.append(line) | |
instructions = ('XYPBCT' | |
'><v^[]{}' | |
'0123456789' | |
'+-%/*()' | |
'ctbw!=') | |
golfed = '' | |
for line in code: | |
golfed += ''.join(c for c in line.split('#')[0] if c in instructions) | |
new_name = filename.split('.')[0] + '-golfed.pb' | |
with open(new_name, 'w') as f: | |
f.write(golfed) | |
print """# [pb](https://esolangs.org/wiki/pb), {} bytes | |
{} | |
~~explanation goes here~~ | |
**Ungolfed:** | |
""".format(len(golfed), golfed) | |
for line in code: | |
print ' ' + line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment