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:

StintPhysical setCompoundInclusive end lap
1M2medium12
2H1hard30

“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.000

The 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:

  1. stint lengths cover exactly 30 laps
  2. stop laps increase and occur before lap 30
  3. every physical set remains in H1, H2, M2, M3, S7
  4. 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

validatebefore lap 1calculate lapfrom stateadd timeincrement agestop if duethen next laprepeat unless final lap; otherwise return trace + total

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:

InputValue
fuel gain0.100 s/lap
stop loss2.0 s
mediumfresh 100.0; wear 0.2/set-lap
hardfresh 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

LapSetAge beforeCalculationLap timeEventCumulative
1M20100.0 − 0.0 + 0.0100.0—100.0
2M21100.0 − 0.1 + 0.2100.1stop +2.0202.1
3H10100.4 − 0.2 + 0.0100.2—302.3
4H11100.4 − 0.3 + 0.1100.2—402.5
5H12100.4 − 0.4 + 0.2100.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.7

If 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.

CompoundFresh paceWear per completed set-lap
Hard92.950 s0.045 s
Medium92.650 s0.090 s
Soft92.400 s0.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/eventSetAge beforeLap timeCumulative
11M21092.650 − .350 + .900 = 93.2001022.175
12M21192.650 − .385 + .990 = 93.2551115.430
stop——+22.0001137.430
13H1092.950 − .420 + .000 = 92.5301229.960
14H1192.950 − .455 + .045 = 92.5401322.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 lapFinishing time
112804.620 s
122804.500 s
132804.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.

M2:1–8 → H1:9–20 → M2:21–30 is legal. On lap 21, M2 resumes at age 8.

SegmentSynthetic segment time
M2, laps 1–8, ages 0–7742.740 s
H1, laps 9–20, ages 0–111112.700 s
M2, laps 21–30, ages 8–17929.175 s
two stops44.000 s
total2828.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.