Thursday, December 3, 2009

Given the time, devise an algorithm to calculate the angle between the hour and minute hands of an analog clock

The important realization for this problem is that the hour hand is always moving. In other words, at 1:30, the hour hand is halfway between 1 and 2. Once you remember that, this problem is fairly straightforward. Assuming you don't care whether the function returns the shorter or larger angle.

0 comments:

Post a Comment