Skip to content

Instantly share code, notes, and snippets.

@hisabimbola
Created May 24, 2015 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisabimbola/3815fdbb726ff0a99f3e to your computer and use it in GitHub Desktop.
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
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