Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to list all possible times in a 12-hour period, where the hour hand overlaps the minute hand completely. This is really a question about three distinct things - to be done in Mathematica - though only the first of the following points really interests me:

  • Finding solutions to an equation with several variables, where each variable has different restrictions on its domain;
  • Formatting those solutions in a convenient format;
  • Using those solutions to draw the actual clocks!

So what we have is two different variables, $h$ and $m$. $h$ is an integer, between $0$ and $11$, and $m$ is a real number, between $0$ and $60$. We want solutions to when $$ 30h - \frac{11m}{2}=0 $$ within those domain restrictions. I have tried using both Solve and Reduce, but neither seems capable of giving me anything more than conditional expressions. So I would like to find all possible solutions, format them in a nice hour:minute format, and maybe even draw the actual clocks corresponding to these solutions. The formatting and drawing are actually not that hard (though elegant, efficient, and different solutions are certainly welcome); I am truly interested in mixing the domains for $h$ and $m$ above, and getting meaningful answers.

Please feel free to tag as you feel appropriate.

share|improve this question
    
Why is $h$ an integer? Isn't it sometimes the case that the hands will overlap when it's, say, 32.5 minutes past six o'clock? You need to represent those times when the hour hand isn't exactly on the hour. –  Verbeia Jan 24 '12 at 0:55
    
This is built in to the equation I'm trying to solve, and is more a factor of the 32.5 minutes than the hour. In particular, $30h+m/2$ is the angle the hour hand makes at $h$:$m$. –  Steve D Jan 24 '12 at 1:31
    
See also: demonstrations.wolfram.com/… –  Daniel Lichtblau Jan 24 '12 at 16:48
add comment

2 Answers

up vote 15 down vote accepted

I don't think it's necessary to use all the apparatus of Solve or Reduce here.

When you think about it, at one o'clock, the hour hand is on the 1, which corresponds to five minutes. So the hands meet a little after five past one. The solution is therefore that $m = 60 (\frac{h}{11})$. Someone else might show how this can be solved explicitly.

Here is a short piece of code that finds the correct times and formats them nicely as "HH:MM:ss.

DateString[{2012, 1, 23, #, 60. (# )/11}, {"Hour12", ":", "Minute", 
":", "Second"}] & /@ Range[0, 11]

{"12:00:00", "01:05:27", "02:10:54", "03:16:21", "04:21:49",
"05:27:16", "06:32:43", "07:38:10", "08:43:38", "09:49:05",
"10:54:32", "12:00:00"}

Edit to include equation solving approach

To do this in a more complex situation that actually involves Solve, something along these lines would work:

soln = m /. First@Solve[30 h - 11 m /2 == 0, m, Reals]

(60 h)/11

All the solutions are actually in the correct domain of $m$ when $h \in\{1,...,11\}$, but here is what you would need to do to check this.

times = Select[Table[{h, N@soln}, {h, 0, 11}], 0 .<= #[[2]] <= 60. &]

Convert to date strings:

strings = DateString[Join[{2012, 1, 23}, #], {"Hour12", ":", "Minute"}] & /@ 
  times

{"12:00", "01:05", "02:10", "03:16", "04:21", "05:27", "06:32",
"07:38",
"08:43", "09:49", "10:54", "12:00"}

Convert to the necessary angle units.

degrees = {1, -6 Degree}*# & /@ times

{{0, 0.}, {1, -0.571199}, {2, -1.1424}, {3, -1.7136}, {4, -2.28479},
{5, -2.85599}, {6, -3.42719}, {7, -3.99839}, {8, -4.56959},
{9, -5.14079}, {10, -5.71199}, {11, -6.28319}}

 Graphics[{Circle[{0, 0}, 0.85], 
  MapThread[
   Text[#1, {Cos[#2 + Pi/2], Sin[#3 + Pi/2]}] &, {strings, 
    degrees[[All, 2]], degrees[[All, 2]]}]}, ImageSize -> 250]

enter image description here

share|improve this answer
    
Yes agreed, this is a much nicer way to do it. But really I was using this as an example of doing something more complicated, where you are trying to solve equations in two variables. One variables is an integer in some range (here 0-12), and the other is a real in some other range (here 0-60). Nevertheless, thanks so much! –  Steve D Jan 24 '12 at 1:47
    
Ok, so then you need to Solve for $m$ in terms of $h$, then substitute the values for $h$ in, then Select the ones that meet the domain criterion for $m$. I can add this to the answer. –  Verbeia Jan 24 '12 at 2:05
    
Thanks, after the edit, this is exactly what I was looking for. –  Steve D Jan 24 '12 at 2:50
add comment

Tutorial on how to overuse Mathematica

Take this as a humorous example of what the usual Mathematica approach looks like. A Goldberg machine of code, so to speak.

Since this is quite a lengthy answer with code pieces spread all over it, making it very inconvenient for copy+paste, I've uploaded the corresponding .nb. You can download it here.


1. Establishing the equation

Establishing is Hebrew and stands for do until happy with trial and error. Trial and error here means coding a clock, which will give us valuable information about the system, for example whether the clock hands meet at all at some point.

polar is a wrapper generating polar coordinates: it maps the interval $[0,1)$ to coordinates on the unit circle. minute/hour then use this map to calculate where the clock's hands should point to: the minute (or hour) hand travels around the circle once in $60$ (or $12\cdot60$) minutes, therefore the parameter is divided by those numbers, making them maps from $[0,60)$ (or $[0,12\cdot60)$) to the unit circle. ticks is the same thing again, only that the ticks should "travel" around the clock once only per half day, which yields a divisor of $12$.

polar[t_] := Through[{Cos,Sin}[-2\[Pi] t+\[Pi]/2]]
minute = polar[#/60]&;
hour = polar[#/(12 60)]&;
ticks = polar[#/12]&;
Manipulate[
    Graphics@Flatten@{
        Circle[],
        Text[#, 1.1 ticks[#]]& /@ Range[12],
        Line[{0.9 ticks[#], ticks[#]}]& /@ Range[12],
        Gray, Thickness[.025], Arrowheads[.1],  Arrow[{{0, 0}, 0.7 hour[t]}],
        Black, Thickness[.01], Arrowheads[.05], Arrow[{{0, 0}, minute[t]}]
    },
    {{t, 0, "Time\n(minutes after midnight)"}, 0, 12*60}
]

Clock

After countless hours of experimentation, I was finally able to determine a position in which (up to numerical precision) the hands did indeed overlap.


2. Solving the system

The bad news is that I have no sense of reason (12/11 hour etc), luckily there's Mathematica at my hand. Let's generate the equations ...

eqns = Thread[minute[t] == hour[t]]
{ Sin[(Pi t)/30] == Sin[(Pi t)/360],
  Cos[(Pi t)/30] == Cos[(Pi t)/360] }

Wonderful! Solve it!

intersections = Sort[t /. FullSimplify@Solve[Flatten@{eqns, 0 <= t < 12 60}, t]]
{0, 720/11, 1440/11, 2160/11, 2880/11, 3600/11, 4320/11, 5040/11, 5760/11, 6480/11, 7200/11}

3. Displaying the results

This result doesn't look much like something a normal person would have his watch display. Let's change that.

dates = DatePlus[{2012,1,23}, {#, "Minute"}]& /@ intersections;
DateString[#, {"Hour", ":" , "Minute", ":", "Second"}]& /@ dates
{00:00:00, 01:05:27, 02:10:54, 03:16:21, 04:21:49, 05:27:16, 06:32:43, 07:38:10, 08:43:38, 09:49:05, 10:54:32}

To make a nice graphical representation of what a watch with 22 fingers looks like, we can simply strip the Manipulate code given above a bit, add multiple hour/minute hands in return, and combine it all into a single graphic:

Graphics@Flatten@{
    Circle[],
    Text[#, 1.1 ticks[#]]& /@ Range[12],
    Line[{0.9 ticks[#], ticks[#]}]& /@ Range[12],
    Gray, Thickness[.025], Arrowheads[.1], Arrow[{{0, 0}, 0.7 hour[#]}]& /@ intersections,
    Black, Thickness[.01], Arrowheads[.05], Arrow[{{0, 0}, minute[#]}]& /@ intersections
}

Final clock

Done. :-)


3. The take away message

  1. Mathematica is fun.
  2. Mathematica can also be useful.
  3. There are two headlines numbered $3$.
  4. FullSimplify is incredibly powerful.
  5. Simple riddles may expand to (arguably) interesting problems when done with sufficient mathematical rigor (polar equations for a clock, seriously?!)
share|improve this answer
    
+1, David, this was hysterical, and completely apt. –  rcollyer Jan 24 '12 at 3:29
    
I have to admit I was kind of surprised this actually yielded the (exact) correct results. –  David Jan 24 '12 at 3:32
1  
+1, hilarious!! –  Verbeia Jan 24 '12 at 3:41
    
What a great answer! I learned quite a bit from this! –  Steve D Jan 24 '12 at 4:58
    
+1 This looks like me solving a Project Euler problem. :-) –  Mr.Wizard Jan 25 '12 at 16:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.