I agree with a sibling comment that physicists often seem to make the best coders, for some reason.
My hypothesis: it's because physicists are rigorously trained to model real-world systems directly. What would be considered an "advanced" modeling problem to most would be an intro problem to a physics student.
Math is absolutely related, but I think the secret ingredient is "mathematical maturity" — the ability to fluidly jump between layers of abstraction. Mathematicians are good at this too, but physicists go a step further: they are trained to ground their abstractions in concrete physical phenomena.
Mathematicians ground systems in axioms, sure. But physicists have to tether models back to reality — to processes and measurements — which turns out to be exactly the skill set that makes for good programmers and system designers.
Huge generalization, obviously.
But personally, I've noticed my own programming ability increases the more physics I learn. Physics gives you a systematic framework to reason about complexity — and physicists get the luxury of a "relatively simple" universe compared to fields like chemistry or biology. They're working with rich systems described by just a few tightly-coupled parameters. And the kicker: a lot of those systems are 100% repeatable, every time.
That kind of structure — and the habit of respecting it — is priceless for engineering.