#Python import sys if len(sys.argv) != 2: print "Usage: QuizDropper.py quiz_file.txt" exit(0) f = open(sys.argv[1], 'r') lines = f.readlines() #Determining max possible scores totals = map(int,lines[0].split()) num_quizes = len(totals) def read_student(line): elems = line.split() name = elems[0] + " " + elems[1] ns = map(int,elems[2:]) return (name,ns) def calc_drop(n,d,ns,ds,x1,x2): new_n = n-ns[x1]-ns[x2] new_d = d-ds[x1]-ds[x2] return float(new_n) / float(new_d) def sum_list(list): total = 0 for i in list: total += i return total def process_student(name,ns,ds): n = sum_list(ns) d = sum_list(ds) best_score = 0 best_pair = [0,1] for i in range(0,num_quizes): for j in range(i+1,num_quizes): #new_score = 0 new_score = calc_drop(n,d,ns,ds,i,j) if new_score > best_score: best_score = new_score best_pair = [i,j] print name, "\t(drop", best_pair[0]+1, best_pair[1]+1, ") \tscore = ", best_score for line in lines[1:]: (name,ns) = read_student(line) process_student(name,ns,totals)