ALERT: IN CASE YOU DOUBT, NO PUN ON "QUINE" IS INTENDED
In regulated horse-racing for gambling, bets called Quinella bets exist and in which a person bet on the first two places of a race. In racecourses, usually there is a display which shows the odds of a specific combination as below:
(This picture is a cropped picture from Hong Kong Jockey Club. QIN stands for Quinella)
Challenge
Write a program or function, receiving either lines of strings or an array, print or return an ASCII Quinella table with the following format:
QUINELLA | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- | 8\1 | 162 | 7.2 | 11 | 109 | 4.5 | 6.0 | 11 | 999 | 11 | | | | | 1 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 9 | 37 | 9\2 | 11 | 999 | 41 | 350 | 75 | 24 | 999 | 31 | | | | | 2 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 10 | 8.2 | 84 |10\3 | 75 | 999 | 85 | 48 | 8.1 | 138 | 191 | | | | | 3 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 11 | | | |11\4 | 45 | 6.4 | 999 | 287 | 473 | 60 | | | | | 4 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 12 | | | | |12\5 | 15 | 8.9 | 40 | 175 | 378 | | | | | 5 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 13 | | | | | |13\6 | 26 | 999 | 15 | 860 | | | | | 6 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 14 | | | | | | |14\7 | 727 | 100 | 37 | | | | | 7 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- | 8 | 9 | 10 | 11 | 12 | 13 | | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
In this challenge, the numbers in the middle are calculated from the input by a specific algorithm, which will be explained later.
Specification
Input: Your program or function must receive one of the two formats as below:
- Lines of Strings: The first line will be
<number of horses> <number of bets>
, following by<number of bets>
lines of<horse 1> <horse 2> <amount of bet>
.
Example:
10 100 1 2 100 3 4 500 5 6 100 7 8 2000 9 10 10 (... 95 more lines)
- Array: An array or tuple, with 3 elements,
[<number of horses>, <number of bets>, <bets>]
, where<bets>
is a 2d array consisting of<number of bets>
elements, each element consists of 3 elements,[<horse 1>, <horse 2>, <amount of bet>]
. As a special rule for functions, passing the tuple as 3 arguments is allowed.
Example:
[10, 100, [ [1, 2, 100], [3, 4, 500], [5, 6, 100], [7, 8, 2000], [9, 10, 10], ... 95 more elements ]]
You may assume all inputs are valid.
You may assume
1 <= <horse 1> < <horse 2> <= <number of horses>
in both cases.You may assume
9 <= <number of horses> <= 14
in both cases.
Processing: The odds for each quinella pair <horse 1>, <horse 2>
(unordered, i.e. 1,2
and 2,1
are considered identical) is calculated as follows:
Odds = <Total bet amount of all pairs> / <Total bet amount of the pair> / 2
Maximum Odds: 999, Minimum Odds: 1.1
In case you doubt, the odds will be 999 if <Total bet amount of the pair> == 0
.
The result should be rounded to the nearest 0.1 if Odds < 9.95
(in this case, the .0
must be retained if necessary), and to the nearest integer if Odds >= 9.95
.
Output: Replace each bold-and-italic number pair with the corresponding odds calculated in the previous step. Leave the cell blank if any of the number in the pair is larger than <number of horses>
.
QUINELLA | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- | 8\1 | 1,2 | 1,3 | 1,4 | 1,5 | 1,6 | 1,7 | 1,8 | 1,9 |1,10 |1,11 |1,12 |1,13 |1,14 | 1 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 9 | 8,9 | 9\2 | 2,3 | 2,4 | 2,5 | 2,6 | 2,7 | 2,8 | 2,9 |2,10 |2,11 |2,12 |2,13 |2,14 | 2 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 10 |8,10 |9,10 |10\3 | 3,4 | 3,5 | 3,6 | 3,7 | 3,8 | 3,9 |3,10 |3,11 |3,12 |3,13 |3,14 | 3 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 11 |8,11 |9,11 |10,11|11\4 | 4,5 | 4,6 | 4,7 | 4,8 | 4,9 |4,10 |4,11 |4,12 |4,13 |4,14 | 4 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 12 |8,12 |9,12 |10,12|11,12|12\5 | 5,6 | 5,7 | 5,8 | 5,9 |5,10 |5,11 |5,12 |5,13 |5,14 | 5 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 13 |8,13 |9,13 |10,13|11,13|12,13|13\6 | 6,7 | 6,8 | 6,9 |6,10 |6,11 |6,12 |6,13 |6,14 | 6 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- 14 |8,14 |9,14 |10,14|11,14|12,14|13,14|14\7 | 7,8 | 7,9 |7,10 |7,11 |7,12 |7,13 |7,14 | 7 -----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+----- | 8 | 9 | 10 | 11 | 12 | 13 | | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
- Each cell is 5 characters wide.
- You must center the odds, and if you cannot balance the margins, make left margin 1 character less wider than right margin.
Test Cases
Here is a TIO driver which generates random test cases. No hard-coded test cases will be provided.
Winning Criteria
Shortest code in each language wins as per the rules of code-golf challenges. No standard loopholes allowed.
9 <= number of horses <= 14
based on the test generator, and the output format? Additionally, is input in the form of a tuple(number of horses, number of bets, [array of bets])
acceptable? \$\endgroup\$[[Int]]
becomes[(Int,Int,Real)]
\$\endgroup\$