Find the nearest clock hands Challenge

Given a number of seconds past midnight, output the smallest angle between any two hands on a clock face, using as few bytes as possible.

You may assume that the number of seconds is always less than 86400.
Angles may be represented in degrees or radians.

A reference solution is at: http://ideone.com/eVdgC0

Test Cases (results in degrees)

0 -&gt; 0
60 -&gt; 0.5
600 -&gt; 5
3600 -&gt; 0
5400 -&gt; 45
6930 -&gt; 84.75
50000 -&gt; 63.333


Clarificarions


The clock has 3 hands: hours, minutes and seconds.
All hands move continuously, thus hour and minute hands can be found between graduations on the clock face.
CJam, 36 35 34 32 30 bytes

riP*30/_60/_C/]2m*::-:mc:mC$3=


The output is in radians. I've verified the solutions for all 86400 possible inputs.

Try it online in the CJam interpreter.

Idea

Since 2&pi; radians is a full lap, each minute/second interval on the clock is 2&pi;/60 = &pi;/30 radians wide.

Thus, dividing the number of seconds by &pi;/30 yields the position of the second hand.

The minute hand moves at one sixtieth of the pace of the second hand, so dividing the result from above by 60 yields the position of the minute hand.

Likewise, dividing the last result by 12 yields the position of the hour hand.

Note that our three quotient from above are not necessarily in the range [0,2&pi;).

By calculating all nine possible differences of the hands' angles, we obtain three 0's (angular distance between a hand and itself) and the six distances between the different hands.

If the closest hands are on a half that does not include 12, one of the differences from above will be the desired output (mod 2&pi;). 

However, at 01:55:30 (for example), the hour hand is at an angle of 1.008 rad (57.75 deg) and the minute hand at an angle of 5.812 rad (333.00 deg) from 12, giving a difference of 4.804 rad (275.25 deg). By subtracting this result from a full lap, we obtain the angle measured "in the other direction", which equals 1.479 rad (84.75 rad).

Now, rather than mapping each angle &theta; in [0,2&pi;) and conditionally subtracting the result from &pi;, we can simply calculate arccos(cos(&theta;)), since cos is both periodic and even, and arccos always yields a value in [0,&pi;).

Skipping over the three smallest results (all zero), the fourth smallest will be the desired output.

Code

ri                             e# Read an integer from STDIN.
  P*30/                        e# Multiply by π and divide by 30.
       _60/                    e# Divide a copy by 60.
           _C/                 e# Divide a copy by 12.
              ]2m*             e# Push the array of all pairs of quotients.
                  ::-          e# Replace each pair by its difference.
                     :mc       e# Apply cosine to each difference.
                        :mC    e# Apply arccosine to each cosine.
                           $3= e# Sort and select the fourth smallest element.


Alternate version (34 bytes)

rd6*_60/_C/]360f%2m*::m360X$f-+$6=


The output is in degrees and no trigonometric functions are used.

Try it online in the CJam interpreter.