g | x | w | all
Bytes Lang Time Link
029UiuaSBCS240728T145015ZEurope20
018MATL190621T202240ZSuever
016Japt190621T173929ZShaggy
059Pyret190709T123939ZMLavrent
054Tcl190623T134844Zvo1stv
045[R]190625T081617ZZahiro M
028Wolfram Language Mathematica190622T095857ZRoman
01605AB1E190625T063946ZKevin Cr
040Python 3190624T142503ZMarcusWo
017><>190622T232324Ztjjfvi
028Perl 6190622T093819Znwellnho
037Perl 5 MListUtil=min p190621T211720ZXcali
012Jelly190621T181417ZNick Ken
045C# Visual C# Interactive Compiler190622T032359ZGymhgy
015Stax190622T034638Zrecursiv
022Charcoal190621T231605ZNeil
043Python 3.8 prerelease190621T202106Zovs
039JavaScript ES6190621T173112ZArnauld
134Alchemist190621T183143ZNitrodon
057Python 3190621T172240ZTheo

UiuaSBCS, 29 bytes

-:180⌵-180◿360/-+⊂0÷12⊢.×6_30

Try it here!

Expects an array, minutes first.

MATL, 18 bytes

30*i5.5*-t360-|hX<

Accepts two inputs of hours followed by minutes. Uses the same method as this answer

Try it at MATL Online

Explanation

      % Implicitly grab first input (hours)
30*   % Multiply by 30
i     % Explicitly grab second input (minutes)
5.5*  % Multiply by 5.5
-     % Take the difference
t     % Duplicate the result
360-  % Subtract 360
|     % Take the absolute value
h     % Horizontally concatenate
X<    % Determine the minimum value
      % Implicitly display the result

Japt, 16 bytes

*FÑ aV*5½
mUa360

Try it

*FÑ aV*5½     :Implicit input of integers U=h and V=m
*F            :Multiply U by 15
  Ñ           :Multiply by 2
    a         :Absolute difference with
     V*5½     :V multiplied by 5.5
mUa360        :Reassign to U
m             :Minimum of U and
 Ua360        :Absolute difference of U and 360

Pyret, 59 bytes

{(h,m):x=(30 * h) - (m * 5.5)
num-abs(num-min(x,360 - x))}

Tcl, 71 74 59 54 bytes

{{h m {x (60*$h-$m*11)%720}} {expr min($x,720-$x)/2.}}

Try it online!

saved 5 bytes by using a lambda expression

[R] , 45 bytes

 function(h,m)min(t=(60*h+m)*5.5%%360,-t%%360)

Wolfram Language (Mathematica), 30 29 28 bytes

5Abs@Mod[#.{6,-1.1},72,-36]&

Try it online!

ungolfed version:

Abs[Mod[#.{30,-5.5}, 360, -180]] &

The argument of the function is # = {h,m} containing the hour and the minute. This length-two list is interpreted as a vector and the dot-product with {30,-5.5} is calculated: #.{30,-5.5} = 30*h-5.5*m. Then we calculate the symmetric modulus of 360 with Mod[#.{30,-5.5}, 360, -180] giving an angle in the interval -180..+180. Abs takes the absolute value thereof.

As all involved operators are linear, we can multiply and divide all appearing numbers however they are most convenient. By pulling a factor of 5 out of the expression and dividing all numbers in the expression by 5, the byte-count is minimized.

05AB1E, 16 bytes

60*+5.5*D(‚360%ß

Takes hours as first input, minutes as second.

Try it online or verify all test cases.

Explanation:

Basically implements the following formula:

$$t = (60h+m)×5.5$$ $$r = min(t\bmod360,-t\bmod360)$$

60*               # Multiply the (implicit) hours-input by 60
   +              # Add it to the (implicit) minutes-input
    5.5*          # Multiply it by 5.5
        D(‚       # Pair it with it's negative
           360%   # Take modulo-360 on both
               ß  # And then pop and push the minimum of the two
                  # (which is output implicitly as result)

Python 3, 40 bytes

lambda h,m:180-abs(180-(h*30-m*5.5)%360)

Try it online!

h*30 - angle between noon and the hour h when the minute is 0; if the hour is equal or greater than 12, this angle can be equal or greater than 360°
m*6 - angle between noon and the minute hand
m*.5 - angle the hour hand moved forward from the full hour after m minutes (e.g: if it's 4:24, the hour hand moved forward 12 degrees from the position it was in at 4 o'clock)
h*30-m*5.5 - one of the two angles between the hour hand and the minute hand; the coefficient for m is 5.5 because m*6-m*.5=m*5.5; this is still not the answer because it can be a value greater than 360° (e.g: if h,m=13,0) or less than 0° (e.g: if h,m=12,30)
(h*30-m*5.5)%360 - this modulo takes into account the cases where the computed value above is not between 0 and 360°; this is still not the answer because it could be the ampler of the two angles, while we want the most narrow
180-abs(180-(h*30-m*5.5)%360) - this is the final result; the general rule is that x-abs(x-y) is equivalent to min(y,x-y), which would give the correct result

><>, 17 bytes

b*$6a**-:0)12,-*n

Try it online! (6:32)

Takes input as h, m on the stack.

Explanation

b*$6a**-:0)12,-*n
b*                Multiplies m by 11
  $               Swaps m & h
   6a**           Multiplies h by 60
       -          Subtracts m & h (v)
        :0)       Checks if v > 0 (b=0/1)
           12,-   Subtracts .5 from b (-.5/.5)
               *  Multiplies v by b (halve & abs)
                n Outputs result
b*                Errors

Perl 6, 28 bytes

((*/3-*/9*.55+2)%4-2).abs*90

Try it online!

Uses a few tricks stolen from other answers and calculates

r = abs((h/3 - m/9*0.55 + 2) % 4 - 2) * 90
  = abs((h*30 - m*5.5 + 180) % 360 - 180)

Perl 5 -MList::Util=min -p, 37 bytes

$_=abs<>*5.5-$_%12*30;$_=min$_,360-$_

Try it online!

Takes input as hours followed by minutes on a separate line because it saved a few bytes.

Jelly, 14 12 bytes

ד<¿‘Iæ%ذAH

Try it online!

A monadic link which takes the time as a list of two integers: hour, minute.

Thanks to @JonathanAllan for saving 2 bytes!

Explanation

ד<¿‘        | Multiply hour by by 60 and minute by 11
     I       | Find difference
      æ%ذ   | Symmetric mod 360 [equivalent to (x + 360) mod 720 - 360]
          A  | Absolute
           H | Half

C# (Visual C# Interactive Compiler), 47 45 bytes

h=>m=>(h=(360+h%12*30-m*5.5)%360)<180?h:360-h

Try it online!

Stax, 15 bytes

Ç╢e╛╦¡uøßmì♪║└├

Run and debug it

Charcoal, 22 bytes

I↔⁻¹⁸⁰﹪⁻׳⁰⁺⁶N×⁵·⁵N³⁶⁰

Try it online! Link is to verbose version of code. Takes input as two integers. Explanation:

             N          First input
           ⁺⁶           Plus literal 6
        ׳⁰             Multiplied by literal 30
       ⁻                Minus
                  N     Second input
              ×⁵·⁵      Multiplied by literal 5.5
      ﹪            ³⁶⁰  Modulo literal 360
  ⁻¹⁸⁰                  Subtracted from literal 180
 ↔                      Absolute value
I                       Cast to string
                        Implicitly print

Python 3.8 (pre-release), 45 43 bytes

-2 bytes thanks to Erik.

lambda h,m:min(x:=abs(h%12*30-m*5.5),360-x)

Try it online!

h%12 - hour in 12-hour format
h%12*30 - angle of hour hand at the full hour
m/2 - angle the hour hand moved in m minutes
h%12*30+m/2 - current position of the hour hand as an angle
m*6 - angle of the minute hand (360°/60 = 6°)

JavaScript (ES6),  41 40  39 bytes

Takes inputs as (h)(m).

h=>m=>((x=4+h/3-m*.55/9)&2?12-x:x)%4*90

Try it online!

How?

Instead of working directly in the range \$[0..360]\$, we define a temporary variable \$x\$ in the range \$[0..4]\$:

$$x=\left|\frac{4h}{12}+\frac{4m}{60\times12}-\frac{4m}{60}\right|\bmod 4$$ $$x=\left|\frac{4h}{12}-\frac{44m}{60\times12}\right|\bmod 4$$ $$x=\left|\frac{h}{3}-\frac{11m}{180}\right|\bmod 4$$

The angle in degrees is given by:

$$\min(4-x,x)\times90$$

However, the formula is implemented a bit differently in the JS code, as we definitely want to avoid using the lengthy Math.abs() and Math.min().

Instead of computing the absolute value, we force a positive value in \$[0..12]\$ by computing:

$$x'=4+\frac{h}{3}-\frac{11m}{180}$$

And instead of computing the minimum, we determine in which case we are by simply doing a bitwise AND with \$2\$ -- and this is why we chose an interval bounded by a power of \$2\$ in the first place.

Alchemist, 134 bytes

_->In_h+In_m+720d+360a+f
h->60d
m+11d->
0m+d+a+0r->b
0a+0x->r
d+b+r->r+a
r+0b->
b+0d+0h+0y->5y
b+0d+5y->x
0b+0d+f->Out_x+Out_"."+Out_y

Try it online!

Explanation

_->In_h+In_m+720d+360a+f

Initial setup. Inputs hours and minutes into h and m, sets current angle d to 360 degrees (720 half-degrees), sets up a to compute the principal angle, and sets the output flag.

h->60d
m+11d->

Each hour adds 30 degrees, and each minute subtracts 5.5 degrees.

0m+d+a+0r->b
0a+0x->r

While the r (reverse) flag is not set, each d atom should move one a atom to b. This occurs after the minutes are all used up, to avoid a "race condition". When there are no a atoms remaining, set r to reverse this flow.

Note that this second rule can trigger multiple times, and can even trigger before the initial setup rule. This does not harm anything, so there's no need to prevent this. The 0x condition handles an edge case: when the input is 6:00, there are no a atoms when the program terminates, but there are x atoms if the final result is at least 1 degree.

d+b+r->r+a
r+0b->

The reverse: when the signed angle is greater than 180 degrees, move b atoms to a to decrease the angle to output. Stop reversing when the angle reaches "360".

b+0d+0h+0y->5y
b+0d+5y->x

When all of the degree atoms are used up, divide by 2 to get the angle to output.

0b+0d+f->Out_x+Out_"."+Out_y

After this is done, output exactly once using the f flag from the initial setup.

Python 3, 58 57 Bytes

-1/-2 Thanks to @Shaggy

h,m=eval(input())
x=(30*h-5.5*m)
print(abs(min(x,360-x)))

Naive implementation, takes input in the form of [6,32]. Some bytes can probably be shaved off the last line especially.

Python 2, 52 50 Bytes

h,m=input()
x=(30*h-5.5*m)
print abs(min(x,360-x))