Given a list of scores (non-negative integers) pre-sorted from greatest to least:
[ 10, 10, 6, 6, 4, 0]
Assign each score an integer rank, beginning with 1 and ascending, such that equal scores have the same rank (i.e. they are tied):
[ 1, 1, 3, 3, 5, 6 ]
In the case of ties, ranks are "skipped," e.g. since the first and second-greatest scores (10 and 10) are tied, they both have rank 1, and rank 2 is "skipped," so the third-greatest score (6) has rank 3.
Output a list of non-descending ranks corresponding to the input scores.
Examples
In: 10 10 6 6 4 0
Out: 1 1 3 3 5 6
In: 10 9 8
Out: 1 2 3
In: 0 0 0
Out: 1 1 1
In: 16 15 15 12 11 11 10 9 9 9 8 2 2 2 0
Out: 1 2 2 4 5 5 7 8 8 8 11 12 12 12 15
Input
Assume all scores will be between 0 and 1,000 inclusive, and the input will have no more than 500 scores. Input can be in whatever format is convenient for your language of choice (including but not limited to STDIN, arguments to a function, an array already stored in a variable, etc.).
Output
Return or store in a variable the resulting ordered list of ranks, or write it to STDOUT in a human-readable way (e.g. 1 2 3
, [1,2,3]
, 1\n2\n3\n
, and { 1, 2, 3 }
are all fine; 123
is not, for want of a delimiter). The input scores may be stored/printed along with their corresponding output ranks, but that's not required.
Restrictions
You may use any standard library your language offers. Standard loopholes apply.
Winning conditions
This is code-golf, so the smallest program (in bytes) wins. In case of a tie, the answer with the most votes wins.
Notes
This is based on a Ruby question on SO that generated some interesting answers, including one very short one. I encourage you to come up with your own solutions before looking there.