Created
December 20, 2015 05:46
-
-
Save SourceCode/58679b1edbc882c6928c to your computer and use it in GitHub Desktop.
Clock Hand Angle Challenge
This file contains 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
<?php | |
$hourAngleRate = 360 / 12; | |
$minuteAngleRate = 360 / 60; | |
function timeAngle($hour, $min) | |
{ | |
global $hourAngleRate, $minuteAngleRate; | |
if ($hour > 12 || $min > 60) return false; | |
$hourDegree = $hourAngleRate * $hour; | |
$minDegree = $minuteAngleRate * $min; | |
return abs($hourDegree - $minDegree); | |
} | |
echo '<pre>'; | |
echo timeAngle(12, 30) . "\n"; | |
echo timeAngle(1, 18) . "\n"; | |
echo timeAngle(9, 43) . "\n"; | |
echo '</pre>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment