7
1
Write the shortest function that takes a two-dimensional square array representing the scores of a chess round, and outputs an array of the Neustadtl scores of the players.
The two-dimensional array is structured so that array[i][j]
is the score earned by the player i against player j.
The Neustadtl score is used to tie-break in chess tournaments when their conventional scores tie. The Neustadtl score is calculated by adding the scores of the player defeated and half of the scores the player drew with.
Here is an example data for a 5 on 5 match.
cs ns
1. X 1 ½ 1 0 | 2½ 4.25
2. 0 X 1 ½ 0 | 1½ 2.5
3. ½ 0 X ½ ½ | 1½ 3.5
4. 0 ½ ½ X 1 | 2 4
5. 1 1 ½ 0 X | 2½ 4.75
where cs
stands for conventional score and ns
stands for Neustadtl score.
For example, the Neustadtl score of the 4th player is:
0(player 1's cs) + ½(player 2's cs) + ½(player 3's cs) + 1(player 5's cs)
= 0(2½) + ½(1½) + ½(1½) + 1(2½)
= 4
For more details and another example data, see its Wikipedia article.
Some notes:
- Assume the diagonal is always zero (
array[j, j] = 0
) - No need to check if the array is square
- No need to check if the data makes sense (a valid scoretable has the property
array[i, j] + array[j, i] = 1, i != j
)
How about
Tr
? – chyanog – 2013-03-24T07:45:12.317@chyanog Hey! Yesss – Dr. belisarius – 2013-03-24T07:52:10.020