- On ProgrammingChallengesForInterview, one of the problems suggested is
- Write a program that given the time of the day (hours, minutes) return the angle between the hands on a clock.
- The warning given when the problem was initially stated was
- Be on the lookout for them asking if they should return just the smaller angle, and the "clever" solution that just outputs 0 because the hands are parallel.
Then someone said:
-
- The angle represented by (hours * 30) - (minutes * 6)?
-
- That's not programming, that's an arithmetic problem.
There are a few things to notice about this.
- If you use integer hours and minutes, as some people will naturally expect, then it's wrong.
- Probably programmers should be able to derive formulae like this.
- The next suggestion - (hours * 30 + minutes / 2.0) - is also wrong.
Then came the first question:
-
- Does the hour hand on your clock snap from hour to hour?
Ah.
If this question is used in an interview, perhaps what we're looking for includes, among other things, the interviewee asking questions about the requirement.
CategoryMath