2

A friend of mine asked me to write a function which, given a time of day and a interval of times, determines whether the first time is within the range accounted for by the second. For the purposes of this discussion, let's simplify his problem and only consider the hour hand of the clock.

Problem Statement: Given an hour $x$ and the interval of time Alice is asleep $[a, b]$, determine whether Alice will be asleep during hour $x$.

I was able to solve his problem by producing a function that essentially does

$$(x - a) \bmod 24 \le (b - a) \bmod 24$$

My question is: what does this expression actually mean from a mathematical standpoint? It solves the problem correctly, but it does so by performing cyclic group subtraction and then comparing the result values, but the comparison is just standard natural number comparison and ignores the (mod 24). Why am I allowed to just drop the group structure when it's convenient, and why does it get the right answer?

Ethan Bolker
  • 95,224
  • 7
  • 108
  • 199

0 Answers0