You are given a table that represents the rankings of S subjects according to a number C of different criteria. The purpose is to
- compute an overall ranking according to a weighted sum of the C ranking criteria,
- using one of those criteria (i.e. columns), T, as tie-breaker.
The rankings are a S×C table of positive integers. The weights for computing the overall ranking are given as an array of non-negative numbers.
Entry (s,c) of the table contains the ranking of subject s according to criterion c; that is the position of subject s when all S subjects are sorted according to criterion c. (Another possible interpretation, not used here, would be: row s tells which user is ranked s-th according to criterion c).
Example
Consider the following table with S=6 and C=2:
1 4 4 5 6 1 3 3 5 2 2 6 Weights are
1.5 2.5 and column T=2 is used as tie-breaker.
The overall ranking for the first subject (first row) is 1*1.5+4*2.5 = 11.5. The overall ranking array is
11.5 18.5 11.5 12 12.5 18 The resulting ranking, which is the output, is then
2 6 1 3 4 5 Note that the first-ranked row is the third, not the first, according to the tie-breaking specification.
Input and output
Use any reasonable format for input and output. The rankings may be a 2D array of any orientation, an array of arrays, or separate arrays. Inputs may be taken in any fixed order.
Input and output rankings should be 1-based (as in the example above), because that's the natural way to speak of rankings.
Output may be a string of numbers with a fixed separator character or an array.
You can write a function or a program.
Test cases
Table, weights, tie-breaking column, output.
--- (Example above) --- 1 4 4 5 6 1 3 3 5 2 2 6 1.5 2.5 2 2 6 1 3 4 5 --- (Three columns) --- 4 4 1 2 3 5 5 1 3 3 5 2 1 2 4 0.5 1.4 0.9 1 3 4 1 5 2 --- (Only one weight is nonzero) --- 1 5 3 3 4 2 5 1 2 4 1 0 2 1 3 4 5 2 --- (Only one column) --- 2 4 1 3 1.25 1 2 4 1 3 --- (Only one row) --- 1 1 1 0.8 1.5 2 3 1