23
2
The solar year is 365 days, 5 hours, 48 minutes, 45 seconds, and 138 milliseconds, according to this video. With the current Gregorian calendar, the rules for leap years are as follows:
if year is divisible by 400, LEAP YEAR
else if year is divisible by 100, COMMON YEAR
else if year is divisible by 4, LEAP YEAR
else, COMMON YEAR
Unfortunately, this method is off by one day every 3216 years.
One possible method of reforming the calendar is the following rule:
if year is divisible by 128, COMMON YEAR
else if year is divisible by 4, LEAP YEAR
else, COMMON YEAR
This has the benefit of not requiring us to change our calendars again for another 625,000 years, give or take.
Say the entire world decides that, starting now, we use this system of every fourth year is a leap year except every 128th year, changing our calendars as follows:
YEAR GREGORIAN 128-YEAR
2044 LEAP LEAP
2048 LEAP COMMON
2052 LEAP LEAP
...
2096 LEAP LEAP
2100 COMMON LEAP
2104 LEAP LEAP
...
2296 LEAP LEAP
2300 COMMON LEAP
2304 LEAP COMMON
2308 LEAP LEAP
How would this affect our day of the week algorithms?
The challenge
- Given a date from the year 2000 to the year 100000, find the day of the week under this new calendar.
- Any input and output format is allowed as long as you clearly specify which formats you are using.
- This is code golf so try to make your solutions as golfy as possible!
Test cases
"28 February 2048" -> "Friday"
"March 1, 2048" -> "Sat"
(2100, 2, 29) -> 0 # 0-indexed with Sunday as 0
"2100-02-29" -> 7 # 1-indexed with Sunday as 7
"28 Feb. 2176" -> "Wednesday"
"1-Mar-2176" -> "Th"
"28/02/100000" -> "F" # DD/MM/YYYYYY
"Feb. 29, 100000" -> 6 # 1-indexed with Sunday as 7
"03/01/100000" -> 1 # MM/DD/YYYYYY and 1-indexed with Sunday as 1
Suggestions and feedback on the challenge are welcome. Good luck and good golfing!
For test case #4, you mean 1-indexed, right? Otherwise there would have to be 8 days in that week. – Sebastian – 2017-11-30T20:37:02.550
Also, you say "good golfing", so is this a #code-golf challenge? If so, put in the winning criteria (e.g. lowest number of bytes/characters) and add that as a tag. – Sebastian – 2017-11-30T20:40:47.507
@Sebastian You are correct on both counts. I've already edited the challenge. Thank you for your feedback – Sherlock9 – 2017-11-30T20:46:27.853
My answer disagrees with the test cases from the year 100000 (labeling them Friday and Sunday, respectively), but I believe my answer over the test cases. I've brute-force checked my answer in two respects over the range 2000 to 100000: that Jan 1 is always the day after Dec 31 of the previous year, and that the years in which Mar 1 is not the day after Feb 28 are precisely the years divisible by 4 but not 128. Can you double-check those test cases? – Misha Lavrov – 2017-11-30T22:20:53.323
1When reading the title I immeadiately though of Matt Parker's video. Nice to see it linked in the thread as well :D – PattuX – 2017-11-30T22:22:22.023
@MishaLavrov I'm getting Saturday for both – ericw31415 – 2017-12-01T01:30:30.940
@ericw31415 They can't both be Saturday, they're two days apart. – Misha Lavrov – 2017-12-01T01:53:38.673
@MishaLavrov Whoops, that was due to a careless "simplification" on my part. I'm now getting Friday and Sunday like you. – ericw31415 – 2017-12-01T02:03:01.767
1Just take the standard day-of-the-week libraries and modify the global constants accordingly, right? ;) – Wildcard – 2017-12-01T04:18:12.477
@MishaLavrov I figured I had 100000 wrong somehow. Thanks for the feedback. – Sherlock9 – 2017-12-01T06:20:48.750
I enjoy seeing how the order of the function parameters is m, d, y for some answers and d, m, y for others––and then there are those implicit parameter answers that apparently like to keep an air of mystery about them. – Daniel – 2017-12-03T02:06:09.037