Day of the Week - Problem
Ever wondered what day of the week you were born on? Or what day Christmas will fall on next year? This problem asks you to determine the day of the week for any given date!
You are given a date as three integers: day, month, and year. Your task is to return the corresponding day of the week as a string from the set: {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.
Key reference point: January 1, 1971 was a Friday. You can use this as your starting point to calculate any other date!
Example: If given day = 31, month = 12, year = 2019, you should return "Tuesday" because December 31, 2019 was a Tuesday.
Input & Output
example_1.py โ Basic Date
$
Input:
day = 31, month = 12, year = 2019
โบ
Output:
"Tuesday"
๐ก Note:
December 31, 2019 was a Tuesday. We can verify this by counting days from January 1, 1971 (Friday) or using the mathematical formula.
example_2.py โ Leap Year
$
Input:
day = 29, month = 2, year = 2020
โบ
Output:
"Saturday"
๐ก Note:
February 29, 2020 was a Saturday. This tests our leap year handling since 2020 is divisible by 4.
example_3.py โ Reference Date
$
Input:
day = 1, month = 1, year = 1971
โบ
Output:
"Friday"
๐ก Note:
This is our reference point given in the problem statement. January 1, 1971 was a Friday.
Constraints
- 1 โค day โค 31
- 1 โค month โค 12
- 1971 โค year โค 2100
- The given date is guaranteed to be valid
- No need to validate input dates
Visualization
Tap to expand
Understanding the Visualization
1
Know Your Reference
January 1, 1971 was a Friday - this is your anchor point
2
Count or Calculate
Either count every day or use math to jump directly to the answer
3
Handle Patterns
Days repeat every 7, leap years add extra days, months have different lengths
4
Get Final Answer
Use modulo 7 to convert total days into day of the week
Key Takeaway
๐ฏ Key Insight: Since days repeat every 7, we only need to find how many days have passed since our reference date (modulo 7). We can either count every day or use mathematical formulas to jump directly to the answer!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code