The problem in brief
Each of 200 bridges is a curve on . For every bridge you are given about 70 surviving points , and the positions (15 to 47 of them) where pillars must be rebuilt. These positions all fall inside one contiguous broken stretch, typically 2 to 4 metres wide, with no surviving point inside it. You must output the missing heights. The statement hints at the twist: the city is "built from mathematical formulas".
How you are scored
With test positions, the error of each prediction is capped at 0.5 and averaged:
So (completely wrong everywhere) gives 0 points and gives the full 100 points: that is the target. The cap means a hopeless bridge costs at most 0.5, so it pays to be exactly right on as many bridges as possible rather than roughly right everywhere. The true heights are hidden on Kattis; we estimate ourselves (see Results).
First look at the data
Plotting a few bridges is the most important step of this problem.
- The shapes are textbook functions: parabolas, cubics, clean sinusoids, decaying oscillations, S-curves, bumps, kinks, staircases.
- For every bridge the values have mean exactly 0 and standard deviation exactly 1 over the training points: the organisers standardised . That is only an affine change , so any family with a free scale and offset absorbs it.
- The decisive test: fit a degree-2 polynomial to bridge 0 and the residual is , machine precision. There is no noise at all. The surviving points are exact samples of a closed-form formula.
That observation changes the nature of the problem. The provided example solution copies the height of the nearest surviving point, and generic interpolation (splines) just draws a smooth bridge across the hole. Both are guessing. If we can recognise the formula, we can compute the hole exactly.
A first baseline
To measure anything without the hidden answers we need our own test. For each bridge we hide the known points lying just next to the real broken stretch (a fake gap of the same width) and predict them from the remaining points. This is harder than the real task, since the fake gap is glued to the real one (the hole to bridge is twice as wide), so our estimates are pessimistic.
| baseline | estimated | estimated score |
|---|---|---|
| nearest surviving point (the organisers' example notebook) | 0.375 | 31 |
| shape-preserving cubic interpolation (PCHIP) | 0.321 | 45 |
Interpolation fails exactly where it matters: a sine wave has a whole trough inside the gap, and a spline cannot know it is there.
The key idea
No noise means a correct model fits perfectly, and a wrong model does not. With 70 exact points, a family with 3 to 7 parameters either reproduces them to or misses them by or more. There is almost nothing in between: the figure below shows the training RMSE of the best family for each bridge, and it splits into two clean worlds separated by a valley around .

So the method is model identification rather than regression:
- Build a library of families: polynomials of degree 1 to 8, , the same plus a linear trend, damped oscillations , chirps , sums of two sines, amplitude-modulated sines, , Gaussian and Laplace bumps, exponentials, kinks and squared ReLUs.
- Fit each family to the surviving points by least squares.
- If some families fit to RMSE , take the one with fewest parameters (Occam's razor: a parabola also "is" a degree-8 polynomial, but the simplest exact explanation is the one to trust).
- Otherwise (no family is exact), choose between the families that fit decently, PCHIP interpolation and nearest neighbour by how well each refills pseudo-gaps cut out next to the real gap.
Why is an exact fit trustworthy? If a family with parameters passes through exact points, the chance that a different function does so by coincidence is negligible: each extra point is an extra equation the coincidence would have to satisfy. Fitting is cheap, and the test is binary.
The one technical difficulty is that the non-linear fits have local minima. A sine fit started at the wrong frequency converges to a wrong, smaller wiggle. Two cures are used:
- For oscillating families, scan a grid of 1 200 frequencies ; for a fixed the model is linear in , so each grid point is a tiny least-squares solve. The best seeds
curve_fit, which refines all parameters together. - For S-curves, bumps and kinks, start
curve_fitfrom a deterministic grid of centres , widths and signs, and keep the best.
fits = {name: fit_family(name, x, y) for name in FAMILIES} # (train RMSE, predictor)
exact = [n for n, (rmse, g) in fits.items() if rmse < 1e-6]
if exact:
best = min(exact, key=lambda n: N_PARAMS[n]) # Occam
return fits[best].predict(x_gap)

Look at bridges 17 and 24: the spline draws a gentle slope across the gap while the true curve dips through a full trough or crest. Those are exactly the points where the capped error would have been 0.5.
The full solution
solution.py (about 150 lines, NumPy and SciPy only):
- For each bridge, sort the surviving points and compute the gap width from the test positions.
- Fit the 22 families (8 polynomials and 14 non-linear forms) with the start strategies above.
- Exact fit found: predict with the simplest exact family (119 of the 200 bridges).
- No exact fit: for each candidate that fits all points with RMSE below 0.05, plus PCHIP and nearest neighbour, hide a window of the gap's width just left and just right of the real gap, refit, and measure the capped error; keep the candidate with the smallest average.
- Print one height per line, in the order of
test.csv.
The whole run takes about 3 minutes on one CPU core.
Results
Estimated on the pseudo-gap protocol described above (the real answers are private; Kattis also re-scores on a hidden 70 % at the end of the contest):
| approach | estimated | estimated score |
|---|---|---|
| nearest surviving point (example solution) | 0.375 | 31 |
| PCHIP interpolation | 0.321 | 45 |
| one global polynomial per bridge, degree 3 / 6 / 8 | 0.273 / 0.223 / 0.204 | 57 / 69 / 74 |
| formula identification + pseudo-gap fallback | 0.129 | 93 |
Where the remaining error lives: the identified formulas are exact on 129 of the 200 validation gaps, covering 63 % of the hidden points, with error or less. On the other 71 bridges (staircases, square waves, aliased high-frequency curves, shapes outside the library) the fallback reaches , barely better than PCHIP (0.37). The score is therefore decided almost entirely by how many formulas you recognise: each extra family that matches a group of bridges converts a 0.35 error into 0. Further gains would come from adding the missing families (floors and sign functions for the staircases, compositions such as for the very irregular ones).
A detail that cost us a bug: with random restarts, the same bridge was sometimes identified and sometimes not. Deterministic start grids made the method reproducible, which matters when a contest re-runs your code.
What to remember
- Plot first, and test for noise. A residual of tells you that you are not doing statistics but recovering an exact law; the right tool changes completely.
- Exact data turns model selection into a yes/no test: a family that reproduces many exact points with few parameters is the formula. Prefer the simplest exact explanation.
- Non-linear least squares needs good starts. Scan the hard parameter (here the frequency) on a grid, solve the linear part exactly at each grid point, then refine.
- Build your own validation that mimics the test. Here: hide a contiguous stretch of known points next to the real gap, never random isolated points, which would make interpolation look far too good.
- Know your metric. A capped error rewards being exactly right on many items more than being approximately right on all.