from heapq import nlargest
from random import Random
SCOREBOARD = 21, 8, 7, 2
class GuessingGame:
def __init__(
self,
player_names,
seed
):
self.player_names = player_names
self.players_n = len(player_names)
self.results = [0] * self.players_n
self.cur_player = 0
self.random = Random()
self.random.seed(seed)
def print_results(self):
for name, score in nlargest(
10,
zip(
self.player_names,
self.results
),
key=lambda x: x[1]
):
print(f"{name}: {score}")
def score(self, amount):
self.results[self.cur_player] += amount
def next_player(self):
self.cur_player = (
(self.cur_player + 1) %
self.players_n
)
def move(self, guess):
assert 0 <= guess <= 10
correct = self.random.randrange(11)
error = abs(guess - correct)
if error < len(SCOREBOARD):
self.score(
SCOREBOARD[error]
)
self.next_player()
def get_oc():
game = GuessingGame((
"Sawyer",
"Ben",
"Kate",
"Hugo",
"John",
"Boone",
"Sayid"
), 2763)
game.move(8)
game.move(5)
game.move(4)
game.move(5)
game.move(4)
game.move(1)
game.move(9)
game.move(6)
game.move(9)
game.move(9)
game.move(9)
game.move(3)
game.move(1)
game.move(6)
return game
if __name__ == "__main__":
get_oc().print_results()
ZnJvbSBoZWFwcSBpbXBvcnQgbmxhcmdlc3QKZnJvbSByYW5kb20gaW1wb3J0IFJhbmRvbQoKU0NPUkVCT0FSRCA9IDIxLCA4LCA3LCAyCgoKY2xhc3MgR3Vlc3NpbmdHYW1lOgogICAgZGVmIF9faW5pdF9fKAogICAgICAgICAgICBzZWxmLAogICAgICAgICAgICBwbGF5ZXJfbmFtZXMsCiAgICAgICAgICAgIHNlZWQKICAgICk6CiAgICAgICAgc2VsZi5wbGF5ZXJfbmFtZXMgPSBwbGF5ZXJfbmFtZXMKICAgICAgICBzZWxmLnBsYXllcnNfbiA9IGxlbihwbGF5ZXJfbmFtZXMpCiAgICAgICAgc2VsZi5yZXN1bHRzID0gWzBdICogc2VsZi5wbGF5ZXJzX24KICAgICAgICBzZWxmLmN1cl9wbGF5ZXIgPSAwCiAgICAgICAgc2VsZi5yYW5kb20gPSBSYW5kb20oKQogICAgICAgIHNlbGYucmFuZG9tLnNlZWQoc2VlZCkKICAgIAogICAgZGVmIHByaW50X3Jlc3VsdHMoc2VsZik6CiAgICAgICAgZm9yIG5hbWUsIHNjb3JlIGluIG5sYXJnZXN0KAogICAgICAgICAgICAgICAgMTAsCiAgICAgICAgICAgICAgICB6aXAoCiAgICAgICAgICAgICAgICAgICAgc2VsZi5wbGF5ZXJfbmFtZXMsCiAgICAgICAgICAgICAgICAgICAgc2VsZi5yZXN1bHRzCiAgICAgICAgICAgICAgICApLAogICAgICAgICAgICAgICAga2V5PWxhbWJkYSB4OiB4WzFdCiAgICAgICAgKToKICAgICAgICAgICAgcHJpbnQoZiJ7bmFtZX06IHtzY29yZX0iKQogICAgCiAgICBkZWYgc2NvcmUoc2VsZiwgYW1vdW50KToKICAgICAgICBzZWxmLnJlc3VsdHNbc2VsZi5jdXJfcGxheWVyXSArPSBhbW91bnQKICAgIAogICAgZGVmIG5leHRfcGxheWVyKHNlbGYpOgogICAgICAgIHNlbGYuY3VyX3BsYXllciA9ICgKICAgICAgICAgICAgKHNlbGYuY3VyX3BsYXllciArIDEpICUKICAgICAgICAgICAgc2VsZi5wbGF5ZXJzX24KICAgICAgICApCiAgICAKICAgIGRlZiBtb3ZlKHNlbGYsIGd1ZXNzKToKICAgICAgICBhc3NlcnQgMCA8PSBndWVzcyA8PSAxMAogICAgICAgIGNvcnJlY3QgPSBzZWxmLnJhbmRvbS5yYW5kcmFuZ2UoMTEpCiAgICAgICAgZXJyb3IgPSBhYnMoZ3Vlc3MgLSBjb3JyZWN0KQogICAgICAgIGlmIGVycm9yIDwgbGVuKFNDT1JFQk9BUkQpOgogICAgICAgICAgICBzZWxmLnNjb3JlKAogICAgICAgICAgICAgICAgU0NPUkVCT0FSRFtlcnJvcl0KICAgICAgICAgICAgKQogICAgICAgIHNlbGYubmV4dF9wbGF5ZXIoKQoKCmRlZiBnZXRfb2MoKToKICAgIGdhbWUgPSBHdWVzc2luZ0dhbWUoKAogICAgICAgICJTYXd5ZXIiLAogICAgIC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