Created
May 9, 2020 12:14
-
-
Save meehatpa/f55a99304d9968a5d386e5aba2ed6cfc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
// Angle from 0000 hrs | |
int hour_hand_angle(int hour, int min) | |
{ | |
return hour * 30 + min / 2; | |
} | |
// Angle from 0000 hrs | |
int min_hand_angle(int hour, int min) | |
{ | |
return min * 6; | |
} | |
int diff(int hour, int min) | |
{ | |
int tmp = hour_hand_angle(hour, min) - min_hand_angle(hour, min); | |
tmp = tmp < 0 ? -tmp : tmp; | |
return (tmp > 180) ? 360 - tmp : tmp; | |
} | |
int main() | |
{ | |
assert(hour_hand_angle(3, 0) == 90); | |
assert(hour_hand_angle(9, 30) == 285); | |
assert(min_hand_angle(10, 30) == 180); | |
assert(min_hand_angle(9, 15) == 90); | |
assert(diff(10, 16) == 148); | |
assert(diff(2, 20) == 50); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment