What day of the week?
What day of the week was I born? Getting a calendar of that year could prove an impossible task, although if you are in front of a computer, there are *nix utilities that will do that for you. But seriously, who has access to a computer with unix or linux when the question pops?
There is a neat algorithm that, without the aid of pen and paper, will let you find the day of the week for any given date. It only takes six simple steps. On each of the first five steps, you come up with a different coefficient. In the last step, you add all those coefficients together and perform a very simple operation that offers a number between zero and six. This number indicates the day of the week:
- The CENTURY step. The century coefficient, which we denote , is computed from the first two digits of the year. The coefficient for 20 is “minus one”, and for any other century, you can obtain the coefficient from the following table:
For example, the first two digits of 1973 are 19: the corresponding coefficient is
- The YEAR step. The year coefficient, which we denote , is computed from the last two digits of the year as the output of the following formula: if is the last two digits of the year, then where indicates the integer part of any given real number.
For example, the last two digits of 1973 are 73. Since the year coefficient is
- The MONTH step: This is the part that takes some memorizing. The month coefficient is given by the table below. Lewis Carroll gave a very nice rule to construct that table:
January is “zero”; February and March are both “three” (the third month); December is “twelve” (the twelfth month). For each month that starts or ends in a vowel, its month number subtracted from ten. For the next month to one of those, the previous coefficient plus the number of days of the previous month.
For example, August has a two in the table. The month coefficient is thus
- The LEAP YEAR step: Every year whose two last digits are a multiple of four is a leap year (except if those two digits are both zero—in that case, leap year occurs only if the whole year is a multiple of four-hundred). In case of leap year and the month being either January or February, we subtract one. Otherwise, zero.
For example, 1973 is not a leap year, so the coefficient is
- The DAY step: The corresponding coefficient , is simply the day of the month.
For August 22, the coefficient is
- In the final step, we add up all the previous coefficients, and compute the remainder after division by seven (this is equivalent to add or subtract seven as many times as necessary so we obtain a number between zero and six). This indicates the day of the week, by the easy correspondence Sunday is zero, Monday is one, and so on.
For example, for August 22, 1973, we have
The remainder is thus 3, and the day of the week is Wednesday.
With the help of the libraries calendar and folding of the package tikz, it is possible to generate this fun calendar printed on an unfolded dodecahedron. The code could not be simpler:
Also, a simple python module that uses this algorithm to compute the day of the week of a given date is included below:
As an example of usage, we make use of the code to find the previous date’s day of the week: