Last active
August 28, 2018 00:32
-
-
Save cory2067/94f978e06776823a1391a68dc463b8b0 to your computer and use it in GitHub Desktop.
Next Code python bee scoring
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
''' | |
Expects an "answer.py" in the same directory containing the answer | |
Example usage: | |
register team: "add=melonpan" | |
correct answer: "team=melonpan stars=3" | |
challenge solution: "team=notmelonpan stars=3 challenge" | |
wrong answer: "team=melonpan wrong" | |
''' | |
teams = {} | |
def score(p): | |
with open('answer.py') as f: | |
code = f.read().split('\n')[:-1] | |
avg = sum([len(l) for l in code])/len(code) | |
return int(max(100, (1+int(p['stars']))*(1000*0.7**(len(code)-1) - 4*avg))) | |
prev = 0 | |
i = '' | |
while True: | |
i = input('> ').split() | |
params = {} | |
for arg in i: | |
if '=' in arg: | |
k,v = arg.split('=') | |
params[k] = v | |
else: | |
params[arg] = 1 | |
if 'add' in params: | |
teams[params['add']] = 0 | |
print("Team {} registered!".format(params['add'])) | |
continue | |
if 'challenge' in params: | |
if score(params) <= prev: | |
print("This solution is worse! 500 point penalty.") | |
teams[params['team']] -= 500 | |
print("Scores: " + str(teams)) | |
continue | |
if 'wrong' in params: | |
print("500 point penalty.") | |
teams[params['team']] -= 500 | |
else: | |
s = score(params) | |
teams[params['team']] += s | |
prev = s | |
print("Awarding {} points".format(s)) | |
print("Scores: " + str(teams)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment