# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1699: Double time

From New Scientist #2866, 26th May 2012 [link]

I woke up one morning last summer near the time of the solstice, and noticed that the clock in the darkened bedroom indicated a time either between 3.40 and 3.45am or between 8.15 and 8.20am – I couldn’t tell which.

When I mentioned this to my eccentric uncle, he produced a defunct clock, which he had altered by making the minute and hour hands identical. He then arranged the hands to a particular setting which corresponded to my bedroom dilemma, and told me that it would be impossible to distinguish, by appearance alone, which of two particular times was being shown by the clock.

Assume that at noon both hands on my uncle’s clock point exactly to the 12 marker. Tell me, to the nearest second, what is the difference (less than 4 hours 40 minutes) between the two times which could have been indicated by my uncle’s clock?

[enigma1699]

### 2 responses to “Enigma 1699: Double time”

1. Jim Randell 23 May 2012 at 7:55 pm

Some simultaneous equations give the solution. Here’s a Python program that computes the answer. It runs in 37ms.

```from math import modf
from enigma import printf, sprintf

# suppose at time t1 (around 3:42am) the hour hand is at position A
# and the minute hand is at B

# then at time t2 (around 8:17am) the minute hand is at position A
# and the hour hand is at B

# so, considering m1 and m2 to be the fractional hours in t1 and t2:
# for A: 3 + m1 = 12 m2
# for B: 12 m1 = 8 + m2

# hence:
# 12 ( 12 m2 - 3 ) = 8 + m2
# 144 m2 - 36 = 8 + m2
# 143 m2 = 44
m2 = 44.0 / 143.0
m1 = 12.0 * m2 - 3.0

t1 = 3.0 + m1
t2 = 8.0 + m2

d = t2 - t1

# print times as "<h>h<m>m<s.ss>s"
def hms(x):
(x, h) = modf(x)
(x, m) = modf(x * 60)
s = x * 60
return sprintf("{h:.0f}h{m:.0f}m{s:.2f}s")

printf("d={d} [t1={t1} t2={t2}]", d=hms(d), t1=hms(t1), t2=hms(t2))
```

Solution: The difference between the times is 4 hours, 36 minutes and 55 seconds.

Note: The exact time of the Summer Solstice in 2011 was 17:16 UTC (on 21st June 2011), which would be 18:16 BST.

• Jim Randell 23 May 2012 at 9:31 pm

Or you can use SymPy to solve the simultaneous equations:

```import sympy
from math import modf
from enigma import printf, sprintf

(m1, m2) = sympy.symbols(('m1', 'm2'))
s = sympy.solve((3 + m1 - 12 * m2, 8 + m2 - 12 * m1))

t1 = 3 + s[m1]
t2 = 8 + s[m2]
d = t2 - t1

# print times as "<h>h<m>m<s.ss>s"
def hms(x):
(x, h) = modf(x)
(x, m) = modf(x * 60)
s = x * 60
return sprintf("{h:.0f}h{m:.0f}m{s:.2f}s")

printf("d={d} [t1={t1} t2={t2}]", d=hms(d), t1=hms(t1), t2=hms(t2))
```