36
4
Given the time in 24 hour format (2359
= 11:59pm
) return the angle between the minute and hour hands on a standard clock (on the face plane, so don't just output 0).
Angles are to be returned in the unit of your choice, should be the smallest possible, and should be a positive number (negative angle converted to a positive value), i.e. you will never have an answer greater than 180 degrees or pi radians.
Some examples to check against (in degrees)
0000
=0.0
0010
=55.0
0020
=110.0
0030
=165.0
0040
=140.0
0050
=85.0
0150
=115.0
0240
=160.0
0725
=72.5
1020
=170.0
1350
=115.0
1725
=12.5
Note: There are a few that have rounding errors, I'm not sure how that should be handled; if we should force consistency across all values.
So I'm assuming the input is always a 4 character string? – None – 14 years ago
That is correct @Mike – Dan McGrath – 14 years ago
3You should include some correct input/output examples including "difficult" input like
0001
,0633
, etc... I notice that many answers actually produce incorrect results. – MtnViewMark – 14 years ago@SimpleCoder: I think a "smallest positive" implies clockwise angle. Counterclockwise would correspond to negative angles. "Smallest" probably means "least multiple of 2*pi". – hallvabo – 14 years ago
It appears that this wasn't originally code-golf. But now that it is, consider revising the accepted answer. – Adám – 9 years ago
1Oh boy, after 5 years my SO notification bar has been going crazy. What a surprising necro, haha. I'll check back in a few days to see if anyone can confirm the APL answer is correct (I'm traveling). I haven't been on this site for ages, but it would sure be nice to be able to mark golfs by language since this has since becoming golfing. – Dan McGrath – 9 years ago
You can download a free APL interpreter from dyalog.com.
– Adám – 9 years agoWhy do everybody golf, when it was not supposed to golf? ) – Nakilon – 14 years ago
1@Nakilon: Can't speak for anyone else, but in my case {1} I missed the tagging (need to establish new habits for this place), {2} golfing is why I came here, and {3} it's kind of simple for anything else, isn't it? – dmckee --- ex-moderator kitten – 14 years ago
A few of the example answers are incorrect and the question is poorly worded ("positive angle only" for instance). I've corrected the examples, clarified the answer, and provided some more examples to highlight possible errors. – None – 14 years ago
2The clockwise angle, or the smallest of the two? – Chris Laplante – 14 years ago
1@SimpleCoder: Smallest, as the question says. – Chris Jester-Young – 14 years ago
00:10
will be0010
or010
? – Nakilon – 14 years agoIt will be
0010
in 24 hour time @Nakilon – Dan McGrath – 14 years ago