# Switching the clock

"Observe the time, would you, Watson, old chap?"

I did as instructed and glanced at the large grandfather clock standing in the corner. "Just a little after 4.42, Holmes."

He nodded, "So when the position of the hands are exactly reversed, it will be a bit after 8.23".

"Just so," I agreed.

"Given that the position of the hour hand is fixed precisely, moment buy moment, by the exact movement of the minute hand, there are only a limited number of times in any given period when the positions of the hands will exactly swap locations. If it was 4.45, there will be no reverse alignment".

"I can see that," I said.

"So how many times do you think the hands of a clock will exactly reverse themselves between 3pm and midnight?"

Since it takes one hour for the minute hand to make one complete revolution, and 12 hours for the hour hand to make one complete revolution, let us denote a time within a 12-hour period from noon to midnight to range from $0$ to $1$. Thus, the position of the minute hand can be expressed as $\{12x\}$, where $\{x\} = x - \lfloor x \rfloor$ denotes the fractional part of $x$. Therefore, reversible positions are exactly those which satisfy $x = \{12y\}$ and $y = \{12x\}$, that is, $x = \{12\{12x\}\} = \{144x\}$. In other words, we want to find $x$ such that $x + k = 144x$ for some integer $k$ ranging from 0 to 143. This can easily be solved to get $x = \frac{k}{143}$. Since we want to find all values $x \in [0.25,1]$, valid values of $k$ range from $[36,143]$, and there are $108$ possible reversible times.

If we wish to discount times where the hands coincide (which technically are reversible, but the reverse time would be itself), we would need to subtract solutions of $x = \{12x\}$, i.e. when $x = \frac{k}{11}$. For values $x \in [0.25,1]$, valid values of $k$ range from $[3,11]$, so we must discard $9$ times, for a new total of $99$ times.
Let the time be $x:y$ with $y=5n+k$, which would look like $5x+(5n+k)/12:5n+k$ on an analog clock. Since it's reversible, $5n+k:5x+(5n+k)/12$ can also be seen, and then the time will be $n:5x+(5n+k)/12$. That means:
$k=(60x+5n+k)/144$
$143k=60x+5n$
Both $x$ and $n$ are integers, so every time $n$ increases, the right-hand side rises by 5, the left-hand side increases by 5/143, and a "reversible time" shows up every 5 5/143 = 720/143 minutes. Starting from noon, the first reversible time after 3pm is seen for $ceil(143*180/720)=36$th time, at $3:180/143$ pm. Midnight comes 9*60=540 minutes after 3pm, so $floor(143*(540-180/143)/720)=107$th time after $3:180/143$ pm will be the last ($108$ in total).
The time "just a little after 4:42" is the $ceil(143*282/720)=57$th reversible time after 0:00, meaning it's $4:42+714/143$.