What are the times during that day that a clock's hands are 180 degrees apart?
Answer by Rachel C
1 : 1:38
<?php
for ($i = 1; $i < 13; $i++) {
print $i . " : ";
print OneEightyCircle($i);
print "
";
}
function OneEightyCircle($hour) {
$min = ($hour + 6) * 5;
if ($min >= 60) $min = $min - 60;
$maxMin = $min + 4;
if (floor($maxMin/12) == floor($min/12)) {
// really only have one option here
$finalMin = $min + floor($min/12);
} else {
// now have two options
$d1 = floor($min/12);
$d2 = floor($maxMin/12);
$htest = ($hour * 5) + $d2 + 30;
if ($htest > 60) $htest = $htest - 60;
if ($htest >= ($d2 * 12)) {
$finalMin = $min + $d2;
} else {
$finalMin = $min + $d1;
}
}
if ($finalMin < 10) {
$time = $hour . ":0" . $finalMin;
} else {
$time = $hour . ":" . $finalMin;
}
return $time;
}
?>