Skip to content

Instantly share code, notes, and snippets.

@auscompgeek
Last active August 29, 2015 14:04
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 auscompgeek/3f8c188464f092f5d187 to your computer and use it in GitHub Desktop.
Save auscompgeek/3f8c188464f092f5d187 to your computer and use it in GitHub Desktop.
A golf statistics calculator, for NCSS Challenge code golf threads.
#!/usr/bin/env python3
import sys
def main():
if len(sys.argv) < 2:
sys.exit('Usage: golfstats.py 1.py ...')
for i in range(1, len(sys.argv)):
if sys.argv[i] == '-':
print(i, '...', sep='. ')
else:
with open(sys.argv[i]) as f:
print(i, stats(f.read()), sep='. ')
def stats(code):
code = code.strip()
# (characters, newlines, semicolons)
return len(code), code.count('\n'), code.count(';')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment