Generate a Python script that solves the following problem.
Inputs: N, C, R
There are N tokens that needs to be distibuted between N players, R times.
Each token has a value:
1: C - 1
2: C - 2
...
C: 0
The rest of the tokens: 0
Tokens 4*C + 1 to N: -1
For example if N is 13 and C is 3:
1: 2
2: 1
3 to 12: 0
13: -1
After R rounds of distribution, each player will have a score which is the sum of the value of each token received. The objective is that the score difference between the players is minimum.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a Python script that simulates the distribution of tokens to minimize the score difference between players, based on the rules you've provided.
🧩 Problem Summary
You have N players and N tokens in each round.
Each round, you distribute all tokens among the players (each gets exactly one token).
Tokens are valued as:
Token 1: C - 1
Token 2: C - 2
...
Token C: 0
Tokens from C+1 to 4*C: 0
Tokens from 4*C + 1 to N: -1
Repeat this distribution for R rounds.
After R rounds, each player has accumulated a score.
The objective is to minimize the maximum difference between any two players' scores after R rounds.
✅ Strategy
To minimize the score differences:
In each round, assign the highest-value tokens to players with the lowest current scores.
This balances out strong tokens across players over time.
We can use a priority queue (min-heap) to always give better tokens to players who are behind.
💻 Python Script
python
import heapq
def generate_token_values(N, C):
"""Generate list of token values based on the given rules."""
token_values = []
for i in range(1, N + 1):
if i <= C:
token_values.append(C - i)
elif i <= 4 * C:
token_values.append(0)
else:
token_values.append(-1)
return token_values
def distribute_tokens(N, C, R):
"""Distribute tokens R times minimizing score differences."""
token_values = generate_token_values(N, C)
# Player scores initialized to zero
player_scores = [0] * N
# Min-heap to keep track of players by their current score
heap = [(score, idx) for idx, score in enumerate(player_scores)]
heapq.heapify(heap)
for round_num in range(R):
# Sort tokens by descending value for this round
round_tokens = sorted(token_values, reverse=True)
# Clear heap and rebuild at start of each round
temp_heap = [(score, idx) for idx, score in enumerate(player_scores)]
heapq.heapify(temp_heap)
assignments = [0] * N # To store which token goes to which player
for token_value in round_tokens:
# Get player with lowest score
score, idx = heapq.heappop(temp_heap)
player_scores[idx] += token_value
assignments[idx] = token_value
# Push updated score back into heap
heapq.heappush(temp_heap, (player_scores[idx], idx))
print(f"Round {round_num + 1} token assignments: {assignments}")
print("\nFinal player scores:", player_scores)
max_score = max(player_scores)
min_score = min(player_scores)
diff = max_score - min_score
print(f"Maximum score difference: {diff}")
return player_scores, diff
# Example usage
if __name__ == "__main__":
N = 13 # Number of players / tokens
C = 3 # Top tier token count
R = 5 # Number of rounds
distribute_tokens(N, C, R)