#Python, Vickrey
Python, Vickrey
def choose(rounds, players, results):
if not results:
return (id(0)/7)%999 + 1
def best(array):
score = lambda x: sum(abs(x-y)**.5 for y in array)
m = max(score(x) for x in range(1, 1000))
return [x for x in range(1, 1000) if score(x) == m]
def second_best(array):
array.extend(best(array))
options = best(array)
return options[(id(0)/7) % len(options)]
results = [map(int, s.split()) for s in results]
counts = {}
for round_ in results:
for number in round_:
counts[number] = counts.get(number, 0) + 1
most_common = sorted([(c, n) for n,c in counts.items()], reverse=True)
to_avoid = [t[1] for t in most_common[:players]]
return second_best(to_avoid)
Makes a list of numbers which have been played often, assumes that everyone else will play optimally and opts for the second best choice given the list.
For example, if the most common numbers are [1, 990, 999]
, then Vickrey inserts the optimal play 200 to give [1, 200, 990, 999]
, then picks the best option for the new array (which is 556).