At h:m the two hands move at different speeds:
- minute hand: 6° per minute, so it sits at
6m - hour hand: 30° per hour plus 0.5° per minute, so it sits at
30(h mod 12) + 0.5m
The angle between them is |hour − minute|. The smaller angle is that value or 360 − that value, whichever is less.
The trap is forgetting that the hour hand creeps forward as the minutes pass. At 3:30 it sits halfway between 3 and 4, not on the 3. Modelling the physical system precisely is the whole problem.