Re:Math and Puzzle Fans Find Magic in Martin Gardner's Legacy
by bumbledraven on Saturday November 02, 2024 @02:37AM
(#42024474)
It turns out that New Year's Day is a bit more likely to fall on Sunday than Saturday. To confirm, here's a bit of simple JavaScript that checks a complete 400-year cycle. You can run it in your browser's console:
const counts = Array(7).fill(0);
for (let year = 2000; year < 2400; year++) {
counts[new Date(year, 0, 1).getDay()]++;
}
console.log(`Number of Saturdays: ${counts[6]}; Number of Sundays: ${counts[0]}`);
Output: Number of Saturdays: 56; Number of Sundays: 58
Note: getDay() returns 0 for Sunday and 6 for Saturday (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...).
Do you recall the solution? It seems like a tricky problem. No approach occurs to me aside from a brute force analysis of the 400 year Gregorian calendar cycle, accounting for the complete leap year rules (under which, e.g., 1900 was not a leap year but 2000 was).