I guess I am lucky to be HACking it this year; as far as I can tell, HAC doesn’t have a modular integer type, so when I made my mistakes I had to face the fact that it wasn’t because I was being too clever but because I was being too stupid.
(Tagging @zertovitch so he can correct me if I’m wrong about HAC.)
Do you mean “every” step of the dial as in, adding or subtracting 1, then checking, for every single turn? I didn’t find that necessary, though I’m not especially proud of what I did, either. I need to look more closely at the approaches using mod that some others have posted. Maybe watch @Max’s bonus, too.
My approach for Part 2 was to figure out how far it takes to get from the knob’s position to 0. Since
Cycles := Distance / 100;
Distance := Distance - Cycles * 100;
Result := Result + abs (Cycles);
if Distance < 0 then
while Distance /= 0 loop
-- HAC lacks Max attribute of integer?
if Position = 0 or else Distance > -Position then
Change := Distance;
else
Change := -Position;
end if;
Position := Position + Change;
Distance := Distance - Change;
if Position < 0 then
Position := Position + 100;
end if;
if Position = 0 then
Result := Result + 1;
end if;
end loop;
else
-- etc.