Skip to content

Commit

Permalink
additional greedy logic?
Browse files Browse the repository at this point in the history
  • Loading branch information
craxrev committed Mar 1, 2020
1 parent daf8119 commit 16457b3
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def _best_scored_lib(self, days):
days_left_after_signup = days - self.LIBS_DICT[i]['t']
if days_left_after_signup > 0:
score, books = self._lib_best_scored_books(i, days_left_after_signup)
if self.idx == 5:
score = (len(books) * score) / self.LIBS_DICT[i]['t']
else:
score /= self.LIBS_DICT[i]['t']
if score > best_lib_score:
best_lib_score, best_lib_idx, best_lib_books = score, i, books

Expand Down Expand Up @@ -90,21 +94,24 @@ def _work(self):

def test(self, idx):

self.idx = idx
self._prepare_input(inputs[idx] + '.txt')
self._work()
self._generate_output(inputs[idx] + '.test')
self.score(inputs[idx] + '.test')
score = self._score(inputs[idx] + '.test')
print('test %s score is : %d' % (chr(97+idx), score))


def solve(self):

for idx in range(len(inputs)):
self.idx = idx
self._prepare_input(inputs[idx] + '.txt')
self._work()
self._generate_output(inputs[idx] + '.out')
self.score(inputs[idx] + '.out')
self.scores()

def score(self, out_filename):
def _score(self, out_filename):

# TODO: verify books for days inconsistencies

Expand All @@ -122,14 +129,28 @@ def score(self, out_filename):
for j in range(libs[i]['b']):
book_idx = libs[i]['books'][j]
score += self.S[book_idx]
print(score)
return score

def scores(self):

scores = []

with open('output/scores', 'w') as scores_file:
for idx in range(len(inputs)):
self._prepare_input(inputs[idx] + '.txt')
score = self._score(inputs[idx] + '.out')
scores.append(score)
scores_file.write('\n'.join(chr(97 + idx) + ' : ' + str(scores[idx]) for idx in range(len(scores))))
scores_file.write('\n\n')
scores_file.write('s: %d' % sum(scores))


def main():

p = Problem()
p.test(5)
#p.solve()
# p.scores()
# p.solve()


if __name__ == '__main__':
Expand Down

0 comments on commit 16457b3

Please sign in to comment.