Introduction:
Beckett Grading Service (aka BGS), is a company which encapusulates and grades Trading Card Game (TCG) cards (i.e. sport cards, Magic The Gathering, Pokémon, Yu-Gi-Oh, etc. etc.). The TCG cards that come in for grading will be checked on four categories (which we will later refer to as subgrades): centering, corners, edges, and surface. These subgrades will be in the range \$[1, 10]\$ in increments of \$0.5\$. Based on these four subgrades, the graded card is also given a final grade (in the same range). This final grade isn't just an average however. To quote the BGS FAQ page (minor note when reading: the grading level/point they're talking about is a step of 0.5):
Here is how we do it!
The overall numerical grade is not a simple average of the four report card grades. Beckett Grading Services uses an algorithm which determines the final grade using the 4 sub grades on the front label of the card holder. The lowest overall grade is the first category to observe because it is the most obvious defect, and the lowest grade is the most heavily weighted in determining the overall grade.Example :
Centering = 9.5; Corners = 9.5; Edges = 9; Surface = 8
Final grade = 8.5The reason that this card received an 8.5 is that even though the Surface grade was an 8 (the lowest grade overall), the 9.5 grades on Centering and Corners were strong enough to bring it up a full point to reach the 8.5 level.
Another example :
Centering = 9.5; Corners = 9.5; Edges = 8.5; Surface = 9
Final grade = 9Upon first glance, it may appear that this card should've received a grade different than a 9. The most this card could receive was .5 (or one-half grade) above the lowest sub-grade. The Edges were the lowest in this case, hence, the card received the overall 9 grade. Even though Centering and Corners received grades of 9.5, a key point to remember is that the minimum requirement to receive a grade of Gem Mint is to have at least three grades of 9.5 and the fourth to be no less than a 9.
Also, please note that the final grade rarely, if ever, exceeds two levels above the lowest of the four characteristic grades. For example, if a card has characteristic grades of Centering 10, Corners 6, Edges 10 and Surface 10, the final grade will be a "7" (of which is exactly two grading levels above the lowest characteristic grade).
Although the algorithm they use to determine the final grade has never been revealed, someone was able to come up with a set of rules as algorithm for determining the final grade based on the four subgrades by looking at as many example graded cards as possible (source):
In pseudo-code:
Sort subgrades in decreasing order
var fourth = fourth number in this order # so the lowest subgrade
var third = third number in this order # so the second to last subgrade - could be equal
# to the lowest of course)
var first = first number in this order # so the highest subgrade
var diff = third - fourth # difference between these two lowest subgrades
var finalGrade # our final grade we're calculating
If diff == 0:
finalGrade = fourth
Else:
If fourth is Edges OR fourth is Surface:
If diff < 1:
finalGrade = fourth + 0.5
Else:
If (diff == 1 AND fourth + 1 >= 9.5)
OR (first - fourth == 1.5 AND first != 10):
finalGrade = fourth + 0.5
Else:
finalGrade = fourth + 1.0
Else-if fourth is Centering:
If diff < 2:
finalGrade = fourth + 0.5
Else-if diff < 4:
finalGrade = fourth + 1.0
Else:
finalGrade = fourth + 1.5
Else(-if fourth is Corners):
If diff < 3:
finalGrade = fourth + 0.5
Else:
finalGrade = fourth + 1
Some examples:
- 9.5 8.5 7.5 9.5 = 8.5:
fourth
number is Edges (7.5);diff
is 1.0. So the final grade becomesfourth + 1.0
. - 10 10 10 8.5 = 9.5:
fourth
number is Surface (8.5);diff
is 1.5. So the final grade becomesfourth + 1.0
(with a different if-else path than the one above) - 9.5 9.5 9 8 = 8.5:
fourth
number is Surface (8);diff
is 1.0;first
number is 9.5. So the final grade becomesfourth + 0.5
. - 5.5 8.5 9 7 = 6:
fourth
number is Centering (5.5);diff
is 1.5. So the final grade isfourth + 0.5
. - 5 7 9 9.5 = 6:
fourth
number is Centering (5);diff
is 2. So the final grade isfourth + 1
. - 4.5 9 9.5 9 = 6:
fourth
number is Centering (4);diff
is 4.5. So the final grade isfourth + 1.5
. - 9 6.5 9 9.5 = 7:
fourth
is Corners (6.5);diff
is 2.5. So the final grade isfourth + 0.5
.
In summary: Corners is punished hardest, Centering next, Surface/Edges the least. How much the overall grade is better than the worst subgrade depends on which subgrade is the worst, and also depends on how much the other three subgrades are better than the worst subgrade, measured by diff
.
Here an ungolfed reference implementation of the described algorithm in Java. (It can also be used to generate more random test cases; see the bottom section of the output.)
Challenge:
Given the four subgrades as input, output the final grade based on the algorithm above.
Challenge rules:
- Input may be in any reasonable format. Can be four separated inputs. A sorted list. Etc. Make sure to state the order of the subgrades centering, corners, edges, surface you've used. Inputs can be as decimal numbers, strings, or other reasonable input-types.
- If your language doesn't have a numeric type that allows decimal values, or if you choose to, you are allowed to take all inputs multiplied by 10 as integers (as long as it's consistent). I.e. instead of
4.5 8 9.5 6.5
you could also take the input as45 80 95 65
. In which case the output is of course similar. Make sure to mention in your answer if you're using integers which are multiplied by 10!
- If your language doesn't have a numeric type that allows decimal values, or if you choose to, you are allowed to take all inputs multiplied by 10 as integers (as long as it's consistent). I.e. instead of
- Output may be returned by a function in any reasonable type, output to STDOUT/STDERR/Exit Code, etc.
- Of course you don't have to follow the algorithm exactly as described above. As long as it gives the correct result for any of the 130321 possible test cases, it's fine to implement it in any way you'd like. If you think hard-coding all possible test cases is shorter in your language of choice, by all means go for it.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Centering Corners Edges Surface = Final grade
10 10 10 10 = 10
10 10 10 9.5 = 10
10 10 9.5 10 = 10
10 9.5 10 10 = 10
9.5 10 10 10 = 10
10 9.5 9.5 9 = 9.5
8.5 9 10 9.5 = 9
8 8 8.5 8.5 = 8
9.5 8.5 9.5 9.5 = 9
5.5 7.5 7.5 7 = 6
9.5 8.5 8.5 9 = 8.5
8 8.5 9 9 = 8.5
9.5 4.5 4.5 2.5 = 3.5
9.5 6 6.5 6 = 6
9.5 7 7 8 = 7
9.5 9.5 9.5 8.5 = 9
7.5 8.5 9 8 = 8
9 8 7 8.5 = 8
10 9.5 9.5 8 = 9
10 9 9.5 9 = 9
10 8 9 9 = 8.5
9.5 8.5 7.5 9.5 = 8.5
9.5 8.5 8.5 6.5 = 7.5
10 10 10 8.5 = 9.5
9.5 9.5 9 8 = 8.5
5.5 8.5 9 7 = 6
5 7 9 9.5 = 6
4.5 9 9.5 9 = 6
9 6.5 9 9.5 = 7
1 1 1 1 = 1
1 10 10 10 = 2.5
10 1 10 10 = 2