Task
Write a program or a function that calculates a week-day name of a date which a user inputs.
Input & Output
Input is a string, YYYYMMDD
.
Example of input values:
20110617 : June 17, 2011 19040229 : February 29, 1904 06661225 : December 25, 666 00000101 : January 1, 0 99991231 : December 31, 9999
You may assume that all inputs are valid. Note that year zero is valid.
Output is an integer between 0
and 6
. Each integer represents a week-day name. You can decide freely which integer represents a week-day name, like this one
0 : Monday 1 : Tuesday 2 : Wednesday ... 6 : Sunday
(in order) or this one
0 : Monday 1 : Wednesday 2 : Sunday ... 6 : Saturday
(not in order).
Test Cases
Input Week-day Output ([0..6 -> Monday..Sunday] is used in this example.) 20110617 Friday 4 19500101 Sunday 6 22220202 Saturday 5 19000228 Wednesday 2 19000301 Thursday 3 19450815 Wednesday 2 19040229 Monday 0 19040301 Tuesday 1 17760704 Thursday 3 20000228 Monday 0 20000229 Tuesday 1 20000301 Wednesday 2 20121223 Sunday 6 00000401 Saturday 5 66660606 Wednesday 2 59161021 Saturday 5
Restriction
You must not use any kind of function/class/... which are related to timestamp or date, like Date
class in Java
/JavaScript
/ActionScript
, or getdate
function in PHP
.
You should use Gregorian calender, which is used by many people now.
Of course, shortest code wins. If two code have same length, then the code with highest votes wins.
(Due: When there's more than 5 codes which has more than (or equal) +1
votes.)
echo 4
. \$\endgroup\$