Created
May 24, 2015 11:27
-
-
Save hisabimbola/3815fdbb726ff0a99f3e to your computer and use it in GitHub Desktop.
Output the times the hour and minute hand of a clock makes a right angle in a day
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
var totalSecInAClock = 24 * 60 * 60 | |
function cal (sec) { | |
var hours = Math.floor(sec / 3600); | |
var minutes = Math.floor((sec - (3600 * hours)) / 60); | |
var seconds = Math.floor((sec - (3600 * hours))) % 60; | |
return { | |
hours: hours, | |
minutes: minutes, | |
seconds: seconds | |
} | |
} | |
function CalTime () { | |
var result = []; | |
for (var i = 0; i < totalSecInAClock; i++) { | |
var time = cal(i); | |
var minNode = (time.seconds / 60) + time.minutes; | |
var hour = time.hours; | |
if (hour > 11) { | |
hour -= 12; | |
} | |
var hourNode = (hour * 5) + minNode/12; | |
var answer = Math.abs(minNode - hourNode); | |
if (Math.abs(answer - 15) < 0.008 || Math.abs(answer - 45) < 0.008) { | |
result.push(time); | |
} | |
} | |
return result; | |
} | |
CalTime() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment