Given a date as three integers — year, month, and day — return the day of the week as a string: "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", or "Saturday".
The date will always be a valid Gregorian calendar date with year >= 1583.
You may use Zeller's congruence or any other algorithm to compute the day. Zeller's congruence works as follows:
month < 3, treat it as month 13 or 14 of the previous year (i.e., add 12 to month, subtract 1 from year)h = (day + floor(13*(month+1)/5) + k + floor(k/4) + floor(j/4) - 2*j) mod 7
k = year % 100 and j = floor(year / 100)h maps to: 0=Saturday, 1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=FridayNote: Some languages produce negative remainders for the modulo operation. Make sure h is non-negative (e.g., use ((value % 7) + 7) % 7).
year = 2024, month = 1, day = 1"Monday"year = 2023, month = 12, day = 25"Monday"year = 2000, month = 2, day = 29"Tuesday"1583 <= year <= 99991 <= month <= 121 <= day <= 31The date is always valid in the Gregorian calendarRun your code to see results
Use Cmd+Enter to run