Skip to content

Instantly share code, notes, and snippets.

@elliott-beach
Created November 21, 2017 03:08
Show Gist options
  • Save elliott-beach/dcf277c71b2a1f27e12a3673da9dce6c to your computer and use it in GitHub Desktop.
Save elliott-beach/dcf277c71b2a1f27e12a3673da9dce6c to your computer and use it in GitHub Desktop.
# Ping [email protected] for questions about using this.
from glob import glob
import os
import re
import sys
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
scores = {}
for line in open('scores.tsv').read().split('\n')[1:]:
line = line.strip()
if line:
bomb, score = line.split('\t')
scores[bomb] = round(int(score) * (100.0 / 70.0), 1)
scores[bomb] = max(scores[bomb], 0)
for f in glob('*_file_'):
submission = glob(f + '/*')
if len(submission) > 1:
print('multiple files submitted')
exit(1)
submission = submission[0]
try:
contents = open(submission).read()
except UnicodeError:
eprint('unicode error', submission)
continue
idNumber = re.findall('\d+', f)[0]
try:
try:
bomb = re.findall('bomb[^\n]*\d+', contents, re.IGNORECASE)[0]
except IndexError:
bomb = re.findall('\n\d+', contents, re.IGNORECASE)[0]
except IndexError:
eprint('no bomb for', f)
eprint(contents)
continue
bombNumber = re.findall('\d+', bomb)[0]
try:
print(idNumber + '\t' + str(scores[bombNumber]))
except KeyError:
eprint('no bomb for', f)
eprint(contents)
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment