Skip to content

Instantly share code, notes, and snippets.

@SourceCode
Created December 20, 2015 05:46
Show Gist options
  • Save SourceCode/58679b1edbc882c6928c to your computer and use it in GitHub Desktop.
Save SourceCode/58679b1edbc882c6928c to your computer and use it in GitHub Desktop.
Clock Hand Angle Challenge
<?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