Week 4: The Race as a Loop#
One state transition at a time
The question#
How does a legal strategy become a finishing time, one lap and one explicit state transition at a time?
This week’s boundary:
- one car; 30 synthetic laps
- dry and uninterrupted
- fixed parameter values; no random draw
- no traffic, overtaking or rival
Same input, same trace, same total. That is deterministic, not necessarily true.
The words the loop needs#
- state — every value needed to advance the race by one lap without hidden memory
- transition — the rule that turns state before one lap into state before the next
- stint — a run of laps on one physical tyre set
- tyre age — laps already completed on that physical set
- finishing time — cumulative elapsed time when the final lap is complete
Finishing time is not finishing position. One car has no position contest.
A strategy is executable data#
M2 → H1 after lap 12 becomes:
| Stint | Physical set | Compound | Inclusive end lap |
|---|---|---|---|
| 1 | M2 | medium | 12 |
| 2 | H1 | hard | 30 |
“After lap 12” means laps 1..12 use M2, the stop fires once, and lap 13
starts on H1.
A compound name alone cannot preserve the age of a refitted physical set.
State before a lap#
At minimum:
lap 1
active_set M2
age_by_set {M2: 0, H1: 0, ...}
next_stop_after 12
cumulative_time 0.000The ages belong to set IDs, not to the compound. Fit M2, run eight laps,
remove it and refit it later: its next age is 8, not 0.
Writing state down prevents a quiet reset.
Validate before lap 1#
Reject unless all four tests pass:
- stint lengths cover exactly 30 laps
- stop laps increase and occur before lap 30
- every physical set remains in
H1, H2, M2, M3, S7 - the compound sequence is in Week 3’s supplied legal set
Rejected input: H1:1–12 → S7:13–30.
It may be quick, but it omits the synthetic mandatory Race specification, medium. Issue 08 Article B6.3.6 requires two dry specifications, including a mandatory Race specification, in this dry bounded case.
One transparent lap equation#
For lap (l), compound (c) and age (a) before the lap:
lap_time = fresh_pace[c] - fuel_gain × (l - 1) + wear[c] × a
- fuel depends on race lap
- wear depends on the physical set’s completed laps
- fresh pace and wear depend on compound
Every coefficient is a SlopU synthetic point value. The equation contains no traffic term and no randomness.
The loop as a state machine#
One ordering matters: finish the lap, age its set, then apply a stop scheduled after that lap.
The transition, without hidden work#
for lap in 1..race_laps:
set, age = active_set, age_by_set[active_set]
time += lap_time(set, age, lap); age_by_set[set] += 1
event = none
if stop_is_after(lap):
time += pit_loss; event = stop; active_set = next_set
append_trace(set, age, event, time)Week 3’s 22.0 s already prices abnormal in- and out-laps against ordinary laps. Adding slow laps here would charge for them twice.
A five-lap fixture we can close by hand#
Synthetic inputs:
| Input | Value |
|---|---|
| fuel gain | 0.100 s/lap |
| stop loss | 2.0 s |
| medium | fresh 100.0; wear 0.2/set-lap |
| hard | fresh 100.4; wear 0.1/set-lap |
Strategy: M2 for laps 1–2, stop, then H1 for laps 3–5.
Expected ages before the laps: 0, 1, 0, 1, 2.
Every fixture row#
| Lap | Set | Age before | Calculation | Lap time | Event | Cumulative |
|---|---|---|---|---|---|---|
| 1 | M2 | 0 | 100.0 − 0.0 + 0.0 | 100.0 | — | 100.0 |
| 2 | M2 | 1 | 100.0 − 0.1 + 0.2 | 100.1 | stop +2.0 | 202.1 |
| 3 | H1 | 0 | 100.4 − 0.2 + 0.0 | 100.2 | — | 302.3 |
| 4 | H1 | 1 | 100.4 − 0.3 + 0.1 | 100.2 | — | 402.5 |
| 5 | H1 | 2 | 100.4 − 0.4 + 0.2 | 100.2 | — | 502.7 |
The stop sits after lap 2, so that row’s cumulative value includes it.
Trace first, total second#
100.0 + 100.1 + 2.0 + 100.2 + 100.2 + 100.2 = 502.7 s
Three useful assertions:
trace ages == [0, 1, 0, 1, 2]
count(trace event == "stop") == 1
trace[-1].cumulative_time == 502.7If a broken loop resets H1 twice or adds the stop on lap 3, at least one
assertion fails before the 30-lap answer can look plausible.
The 30-lap SlopU inputs#
Fuel gain: 0.035 s/lap. Pit loss: 22.0 s.
| Compound | Fresh pace | Wear per completed set-lap |
|---|---|---|
| Hard | 92.950 s | 0.045 s |
| Medium | 92.650 s | 0.090 s |
| Soft | 92.400 s | 0.160 s |
Race inventory: H1, H2, M2, M3, S7; medium mandatory.
Medium’s wear and the pit loss are inherited synthetic estimates. We pin them to point values here, discarding their measured uncertainty so this loop stays deterministic.
Around the stop after lap 12#
Strategy: M2:1–12 → H1:13–30.
| Lap/event | Set | Age before | Lap time | Cumulative |
|---|---|---|---|---|
| 11 | M2 | 10 | 92.650 − .350 + .900 = 93.200 | 1022.175 |
| 12 | M2 | 11 | 92.650 − .385 + .990 = 93.255 | 1115.430 |
| stop | — | — | +22.000 | 1137.430 |
| 13 | H1 | 0 | 92.950 − .420 + .000 = 92.530 | 1229.960 |
| 14 | H1 | 1 | 92.950 − .455 + .045 = 92.540 | 1322.500 |
The hard set starts at age zero. Race lap does not.
Close both segments#
For 12 medium laps, ages and (lap − 1) both run 0..11:
12×92.650 + (0.090−0.035)×(0+...+11) = 1115.430
For 18 hard laps, race-lap terms run 12..29; set ages run 0..17:
18×92.950 − 0.035×(12+...+29) + 0.045×(0+...+17)
= 1673.100 − 12.915 + 6.885 = 1667.070
1115.430 + 22.000 + 1667.070 = 2804.500 s.
Sweep, then explain the tie#
For the legal M2 → H1 order:
| Stop after lap | Finishing time |
|---|---|
| 11 | 2804.620 s |
| 12 | 2804.500 s |
| 13 | 2804.515 s |
Reverse order; stop after lap 18:
H1(1–18) + M2(19–30) + stop
= 1674.630 + 1107.870 + 22.000 = 2804.500 s
The orders tie because this additive one-car model assigns no value to track position.
A legal two-stop refit#
M2:1–8 → H1:9–20 → M2:21–30 is legal. On lap 21, M2 resumes at age 8.
| Segment | Synthetic segment time |
|---|---|
| M2, laps 1–8, ages 0–7 | 742.740 s |
| H1, laps 9–20, ages 0–11 | 1112.700 s |
| M2, laps 21–30, ages 8–17 | 929.175 s |
| two stops | 44.000 s |
| total | 2828.615 s |
Resetting refitted M2 to age zero would erase 7.200 s of wear and invent a
faster tyre. Set identity is part of the state for a reason.
What 2804.500 does not mean#
The loop answers one question: which supplied legal strategy gives this one car the smallest elapsed time under fixed point parameters?
It does not see another car, a rejoin position or the cost of overtaking. It also discards the uncertainty around Week 3’s 22.0-second stop estimate and Week 2’s medium wear estimate.
Assignment 1 calls this model fitness: the recommendation must answer the question it claims, obey the regulations and name what it omits. A correct sum for the wrong question still fails that test.
What passes forward#
You now have a deterministic evaluator that:
- validates a supplied strategy before running it
- preserves state by physical set ID
- returns a lap trace and a checkable finishing time
- names the effects held outside its boundary
Week 5 adds other cars, traffic and overtaking cost. The stop lap that wins on finishing time will lose on finishing position.
Your lab: implement the transition, reproduce 502.7 s and 2804.500 s,
reject an illegal row, and state the boundary in two sentences.