Skip to content

Instantly share code, notes, and snippets.

@undergroundmonorail
Created November 24, 2015 23:38
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 undergroundmonorail/e9d3a33c0026e6e5ec01 to your computer and use it in GitHub Desktop.
Save undergroundmonorail/e9d3a33c0026e6e5ec01 to your computer and use it in GitHub Desktop.
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