# Enigmatic Code

Programming Enigma Puzzles

## Puzzle #28: A well-timed nap

I keep an analogue clock by my bed. One afternoon, I had a nap. When I drifted off to sleep, the minute hand was pointing directly at one of the 12 numbers on the clock face, and the number of minutes past the hour was exactly the same as the angle (in degrees) between the hour and minute hands.

Later that day, when I woke up, I noticed the same was true again.

How long had I been asleep?

[puzzle#28]

### 2 responses to “Puzzle #28: A well-timed nap”

1. Jim Randell 2 November 2019 at 7:20 am

This Python program runs in 89ms.

Run: [ @repl.it ]

```from fractions import Fraction as F
from enigma import irange, printf

# consider times in 5 minute intervals
for t in irange(5, 715, step=5):
(h, m) = divmod(t, 60)

# compute the angles of the hour and minute hand
# and the number of degrees between them
(H, M) = (F(t, 720), F(m, 60))
d = 360 * abs(H - M)

# find when the number of degrees is the same as
# the number of minutes
if d == m:
printf("{h:2d}:{m:02d} -> H={H} M={M}, d={d}")
```

Solution: You had been asleep for 3 hours, 20 minutes.

The first time was at 3:20pm. The hour and minute hands being 20° apart.

The second time was at 6:40pm. The hour and minute hands being 40° apart.

2. GeoffR 6 November 2019 at 8:15 pm
```# Clock times/angles
#
# For hourly intervals the hour hand covers 30 degrees in 1 hour
# Also, for every minute, angle coverage for the hour hand
# = 360/(12 * 60) = 1/2 degree/min
#
# The minute hand covers 360 degrees in one hour
# ie coverage rate = 360/60 = 6 degrees/min
#
# Odd minute hands eg 5, 15, 25 etc have been excluded as formula
# below assumes even integer minutes for integer angles
#
# Let the minute hand be ahead of the hour hand

for m in range(10, 60, 10):
for hr in range(1, 12):
# angle (A) between hands = minute hand - hour hand (angles)
A = m * 6 - (hr * 30 + m // 2)

# the number of minutes past the hour was exactly the same
# as the angle (in degrees) between the hour and minute hands.
if A == m:
print(f"Hr={hr}, Min={m}, Angle between hands={A} deg")

# Hr=3, Min=20, Angle between hands=20
# Hr=6, Min=40, Angle between hands=40
# Time asleep = 6.40 - 3.20 = 3hr 20min

```

This site uses Akismet to reduce spam. Learn how your comment data is processed.