user
Background

In three recent races at Rosetta Park, the results have been:

*Race 1*

| Pos | Horse | Weight | Dist | Sex |
| --- | --- | --- | --- | --- |
| 1 | A | 9.00 | 0.0 | Colt |
| 2 | B | 8.06 | 2.0 | Filly |
| 3 | C | 9.04 | 1.5 | Colt |

Time 1 minute 36.0 seconds

*Race 2*

| Pos | Horse | Weight | Dist | Sex |
| --- | --- | --- | --- | --- |
| 1 | D | 8.10 | 0.0 | Filly |
| 2 | E | 9.03 | 1.0 | Colt |
| 3 | F | 9.07 | 3.0 | Colt |

(F was slowly away and lost 2 lengths at the finish as a result)

Time 1 minute 36.4 seconds

*Race 3*

| Pos | Horse | Weight | Dist | Sex |
| --- | --- | --- | --- | --- |
| 1 | G | 8.04 | 0.0 | Colt |
| 2 | H | 8.10 | 1.5 | Colt |
| 3 | I | 9.05 | 0.5 | Filly |

Time 1 minute 35.8 seconds

It is assumed that:

1. Weights carried are expressed in stones and pounds (traditional in US and UK racing) where 1 stone equals 14 pounds.

2. The distances are the actual distances between horses at the finish of the race.

3. All races are run at 1 mile in similar going and weather conditions and the time shown is the time taken by the winner to run the race.

4. 2 pounds slows a horse down by 1 length at the finish.

5. 1 second is equivalent to 5 lengths at the finish.

Task

All 9 of these horses, plus a further horse J, are due to compete against each other in Race 4 at Rosetta Park again over 1 mile and in similar conditions to the earlier races. Colts will carry 9.00 and fillies 8.11.

Suppose that:

1. Horse B has been moving well on the galops and her trainer thinks she has improved 4 pounds since her last outing.

2. Horse C has had a setback in training and his trainer expects him to perform 4 pounds below his best.

3. Horse H is being ridden by the champion jockey which is expected to improve his performance by 3 pounds compared to what it would otherwise have been.

4. Horse J, a filly, has never run before but her performance on the galops suggests she can run 1 mile in 1 minute 35.8 seconds when carrying 8.11.

Other things being equal (which they seldom are in actual horse racing!) what would you ***expect*** the **full result** of Race 4 to be including the **time** of the winner?
assistant
I know nothing about horse racing and/or handicapping. This is mostly a straightforward translation of the logic from Go though I did take certain liberties with formatting and layout.

```
my %card;
%card<a> = { name => 'Alberta Clipper',       :sex<M>, rating => 100 };
%card<b> = { name => 'Beetlebaum',            :sex<F>, rating => %card<a><rating> - 8 - 2*2 };
%card<c> = { name => 'Canyonero',             :sex<M>, rating => %card<a><rating> + 4 - 2*3.5 };
%card<d> = { name => 'Donnatello',            :sex<F>, rating => %card<a><rating> - 4 - 10*0.4 };
%card<e> = { name => 'Exterminator',          :sex<M>, rating => %card<d><rating> + 7 - 2*1 };
%card<f> = { name => 'Frequent Flyer',        :sex<M>, rating => %card<d><rating> + 11 - 2*(4-2) };
%card<g> = { name => 'Grindstone',            :sex<M>, rating => %card<a><rating> - 10 + 10*0.2 };
%card<h> = { name => 'His Honor',             :sex<M>, rating => %card<g><rating> + 6 - 2*1.5 };
%card<i> = { name => 'Iphigenia in Brooklyn', :sex<F>, rating => %card<g><rating> + 15 - 2*2 };
%card<j> = { name => 'Josephine',             :sex<F>, rating => Nil };

# adjustments to ratings for current race
%card<b><rating> += 4;
%card<c><rating> -= 4;
%card<h><rating> += 3;
%card<j><rating> = %card<a><rating> - 3 + 10*0.2;

# adjust filly's allowance
# initialize carry weights
for %card {
    .value<rating> += 3 if .value<sex> eq 'F';
    .value<weight> = (.value<sex> eq 'M') ?? 9.00 !! 8.11
}

my ($previous, $position, $leader) = 0;
say "Pos Horse         Name           Weight   Back    Sex    Time";

for %card.sort( -*.value.<rating> ) {
    FIRST $leader = $_;
    ++$position if $previous != .value.<rating>;
    $previous = .value.<rating>;
    .value<back> = ($leader.value<rating> - .value<rating>) / 2;
    .value<time> = 96 - (.value.<rating> - 100) / 10;
    printf "%2d    %s   %-22s  %.2f    %.1f    %-6s %s\n", $position, .key, .value<name>, .value<weight>,
      .value<back>, .value<sex> eq 'M' ?? 'colt' !! 'filly', .value.<time>.polymod(60 xx*).reverse.join: ':';
}

```

Output:

```
Pos Horse         Name           Weight   Back    Sex    Time
 1    i   Iphigenia in Brooklyn   8.11    0.0    filly  1:35.4
 2    j   Josephine               8.11    2.0    filly  1:35.8
 3    a   Alberta Clipper         9.00    3.0    colt   1:36
 4    f   Frequent Flyer          9.00    3.5    colt   1:36.1
 5    h   His Honor               9.00    4.0    colt   1:36.2
 6    e   Exterminator            9.00    4.5    colt   1:36.3
 7    d   Donnatello              8.11    5.5    filly  1:36.5
 7    b   Beetlebaum              8.11    5.5    filly  1:36.5
 8    c   Canyonero               9.00    6.5    colt   1:36.7
 9    g   Grindstone              9.00    7.0    colt   1:36.8
```