What day of the week is your birthday?
Sunday
 11%  [ 1 ]
Monday
 0%  [ 0 ]
Tuesday
 33%  [ 3 ]
Wednesday
 11%  [ 1 ]
Thursday
 11%  [ 1 ]
Friday
 11%  [ 1 ]
Saturday
 22%  [ 2 ]
Total Votes : 9

WARNING: The following post includes math concepts and calendar calculations that certainly are NOT for the faint of heart. Razz
As well, at request of c4ooo, I have put the equivalent mathematical equations below each method. Please don't hate me...I eat my cereal dryyyyyyyy Razz


No, not that kind of Doomsday Razz

As a geek, I have some weird, strange, burning obsessions from time to time. A lot of these have to do with math. This time, it is calendar math. Specifically, a way to calculate the day of the week for any given date. Since we haven't adopted the World Calendar system yet, it's hard to find the day of the week if you're given a random date. For example, what day of the week was March 10, 1985? Don't use a calendar![1]

See, it's hard to figure it out. And you only have a ~14.28% chance of guessing randomly, which isn't great. So what do we do? Well...in short, that depends on who you're talking to.

Purely Mathematical Methods

Math is a wonderful tool. You can use it for many different practical purposes...including and especially finding the day of the week. Here are a few popular methods for computing this.

Zeller's Congruence

Christian Zeller is a German mathematician, who specialized in this sort of mathematics. He had created a method for calculating the day of the week, given in a formula that goes like this:


The one disadvantage of this method is the unusual month counting convention; any date in January or February is treated as months 13 and 14 in the previous year. However, feeding in the "correct" numbers for month, day, and year will adjust for you.

Gauss' Algorithm

Johann Carl Friedrich Gauss, another German mathematician, had described a method for calculating the day of the week for January 1st in any given year (only applicable to the Gregorian calendar), which was never published. The formula is this:


There have been modifications made to this to apply to any date, instead of only January 1st, which works in any calendar system. One such modification is as follows:


Mike Keith's C expression

In 1990, an American mathematician and constrained-writing author named Mike Keith published the following terse self-contained C expression for calculating the day of the week of any day in the Gregorian calculator:

Code:
(d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7

This is equivalent to the following mathematical expressions:

This is equivalent to the following TI-BASIC code (with month, day, and year stored in M, D, and Y, and the result will be in Ans)[2]:

Code:
:Y-(M<3
:round(7fPart((int(23M/9)+D+4+Y+int(Ans/4)-int(Ans/ᴇ2)+int(Ans/400)-2(M≥3))/7),0


Mental Calculation Methods

Just in case you don't have a high-speed computer (or TI-83+ calculator) with you at all times, here are some methods ENTIRELY involving memorization and mental calculation. You know...if you're into that sort of thing Wink

Carrollian Method
Charles Lutwidge Dodgson (aka Lewis Carroll, famous for Alice's Adventures in Wonderland and Through the Looking Glass) was an insane writer by day, and an insane mathematician by day also. He had discovered his own method of determining this (which was in Martin Gardner's book The Universe in a Handkerchief: Lewis Carroll's mathematical recreations, games, puzzles, and word plays ), which goes as follows (my attempt to put it in clear English language):
    Calculate 4 numbers based on the century, the years past the century, the month, and the day of the month.
    #1: Century
      For "Old Style" (Julian[3]; valid up to September 2, 1752[4]), subtract the century from 18.
      For "New Style" (Gregorian; valid from September 14, 1752 onwards[4]), divide the century by 4, subtract the remainder from 3, then double that.

    #2: Year
      Add the number of "dozens" that go in the year, the remainder, and the number of 4s that go in that remainder.

    #3: Month
      If the month is January, the number is 0.
      If the month is February or March, the number is 3.
      If the month is December, the number is 12.
      If the month starts or ends in a vowel (y excluded), subtract the month number from 10 (i.e. April is month 4, so for April, 10-4=6).
      For any other month, take the number for the month before it, and add the number of days in that month (i.e. April=6, so May=6+30=36).

    #4: Day
      The item is simply the day number.
      HOWEVER, you must subtract 1 if the date is January or February in a leap year.
      Reminder: Every year divisible by 4 is a leap year, except an even century in "New Style" (Gregorian) where the number of centuries is not divisible by 4 (i.e. 1976 is, 2000 is, 1900 is not).

    Sum these 4 numbers, divide by 7, and take the remainder.
    The total is the day of the week (0=Sunday, 1=Monday, etc.)


Examples:

September 18, 1783 (Gregorian)
17/4=4, remainder 1. 3-1=2. Double 2 is 4.
83/12=6, remainder 11. 11/4=2, remainder 3. 6+11+2=19.
The number for August is 10-8=2. August has 31 days. 2+31=33.
The day is 18.
4+19+33+18=74. 74/7=10 remainder 4.
Therefore, September 18, 1783 was a Thursday.

February 23, 1676 (Julian)
18-16=2.
76/12=6 remainder 4. 4/4=1. 6+4+1=11.
The number for February is 3.
The day is 23, but subtracting 1 (because 1676 is a Julian leap year) gives 22.
2+11+3+22=38. 38/7=5 remainder 3.
Therefore, February 23, 1676 was a Wednesday.

This is very cryptic, and hard to understand why it works (vowels in a month name have significance?), but it works!

Relevant formulae for "Carrollian" method:


Doomsday
A much-simpler-to-understand-why-it-works formula comes from John Horton Conway (famous for his cellular automaton called The Game of Life[5]), and is called the Doomsday Algorithm (named so because he wanted the name to end in -day, and "Dooms-" was the first thing that popped in his head). The principle is this: "Doomsday" is the day of the week of the last day in February in any year, and many easy-to-remember dates fall on Doomsday each year.

A list of some memorable Doomsdays in a year:

January - 3/4
February - 28/29
March - "0"
April - 4
May - 9
June - 6
July - 11
August - 8
September - 5
October - 10
November - 7
December - 12

You can remember January as "the 3rd for 3 years, and the 4th every 4th".
You can remember February as simply the last day of February.
You can remember March as the last day of February (the day before March 1, i.e. "March 0").
You can remember all other even months as being the same number for the month and day (4/4, 6/6, 8/8, 10/10, 12/12).
You can remember all other odd months with the mnemonic "I work 9 to 5 at 7-11[6]" (5/9, 9/5, 7/11, and 11/7 are all Doomsdays).

All of the dates above (and many more, yet less memorable, ones) all fall on Doomsday in a year.

To calculate Doomsday, Conway presents this method:
    Take the "anchor day" for the century from a lookup table.
    Century mod 4[7] - Anchor day
    0 - Tuesday
    1 - Sunday
    2 - Friday
    3 - Wednesday
    e.g. From 1900 to 1999, the century mod 4 is 19 mod 4 = 3, so the anchor day is Wednesday.

    Add the number of "dozens" that go in the year, the remainder, and the number of 4s that go in that remainder.[8]
    Count that many days from the anchor day. That day is Doomsday.
    e.g. For 1958, 58/12=4, remainder 10. 10/4=2, remainder 2. 4+10+2=16=2 mod 7.
    2 days from Wednesday=Friday.

From here, it's a matter of day and week counting in your head from the Doomsday and dates you've remembered.

Relevent formulae for Conway Doomsday method:


"Odd+11"
Of course, there's always a better way Razz , and in this instance, the processes of dividing by 12 and 4 in step 2 of BOTH mental methods so far can be simplified further for mental calculation. It's been done three times to my knowledge, but one of the easiest methods, called the Odd+11 method, is described here:
    Let Y be the 2-digit year.
    If Y is odd, add 11.
    Divide Y by 2.
    If Y is odd, add 11.
    Take Y mod 7.
    Get the 7's complement, i.e. subtract from 7 (unless the number is 0, in which case the 7's complement is 0).
    The final result is your offset.
    e.g. For 1958:
      58 is even, so do nothing.
      58/2=29.
      29 is odd, so 29+11=40.
      40 mod 7=5.
      7-5=2.

Relevant formulae for Odd+11 Doomsday method:


I have a challenge for you: take your birthday (or any other day, so long as you tell me its significance), and find the day of the week it occurred on. Use any of the methods described above, but show your work!

Example: My birthday is January 23, 2001.
Using Doomsday with the Odd+11 method:
Anchor day for 2000 = Tuesday
1 is odd, so 1+11=12.
12/2=6.
6 is even.
7's complement of 6 is 1.
Doomsday 2001 = Tuesday+1 = Wednesday.
Closest memorable Doomsday: January 31 (common year)
January 31, as well as January 31 - 1 week = January 24, is a Wednesday.
January 23 is 1 day before January 24.
Therefore, January 23 is 1 day before Wednesday = Tuesday.

Well, that's the end of my rant about my latest math geek obsession. Have fun with it, and I hope you find it useful! Also, if you have any questions, ask me and I'll explain.

[1]: It's a Sunday.
[2]: I actually wrote this code back in November 2013! Wow, I guess this "obsession" of mine is old Razz
[3]: Julian is referring to New Style Julian, which means that the New Year starts on January 1 (in contrast to Old Style Julian, which means that the New Year starts on March 23).
[4]: September 2, 1752 in Julian is the day before September 14, 1752 in Gregorian. The switch between calendar systems in most regions (not all) happened between those days. That's right, there's another calendar discrepancy to worry about. Razz
[5]: You lost the game.
[me=JWinslow23]runs Razz[/me]
[6]: 9:00 AM to 5:00 PM are traditional working hours, and this has evolved into the slang expression "9 to 5". 7-Eleven is a chain of convenience stores around the world.
[7]: mod refers to modular arithmetic, i.e. numbers wrapping around after a certain point. For example, 8 bit numbers on an NES or TI-84+ work in modulo 256 arithmetic, because values go from 0 to 255, and wrap around.
[8]: Yes, this step is the same as in the Lewis Carroll algorithm! Both are actually a simplification of the "true" formula, y+int(y/4) . It's hard to divide large values by 4 in your head.
Winsy, I think I love you.
...umm...thank...you? Confused
XD Let me explain:

I just started looking at this kind of stuff and was getting really confused, but your explanation cleared a lot of stuff up. Also I'm feeling rather sentimental Razz
WHAAAAAAT??? You lost me about halfway through.
...DOOMSDAY!!
Yeah, I made a program for this.. but, ya know, over 550 bytes later....... Yeah......
But does your thingy do just years 1000 - 9999 or every year possible?
pimathbrainiac wrote:
XD Let me explain:

I just started looking at this kind of stuff and was getting really confused, but your explanation cleared a lot of stuff up. Also I'm feeling rather sentimental Razz

Ah, OK. Thank you.
Hactar wrote:
WHAAAAAAT??? You lost me about halfway through.

Exactly what don't you get? Explain.
GTemples27 wrote:
...DOOMSDAY!!
Yeah, I made a program for this.. but, ya know, over 550 bytes later....... Yeah......
But does your thingy do just years 1000 - 9999 or every year possible?

I made a TI-BASIC Doomsday program, which was 730 bytes minus the header (of course, I used quite a few lowercase letters). I'm curious as to how you implemented it.

And these methods should work with any year at all, but of course taking consideration the different calendar systems, as well as Year 0 not existing (0 would mean 1 BC). The Gregorian calendar repeats every 400 years, and the Julian calendar every 28 years. Smile
JWinslow23 wrote:

I made a TI-BASIC Doomsday program, which was 730 bytes minus the header (of course, I used quite a few lowercase letters). I'm curious as to how you implemented it.


Hmmm... well... let's inspect the source code and see if we can remember how it works, hmm?

Week twice is Str0
Year is Str1
Last 2 digits of year is Z
Remaining digits are X
iPart(Z/12) is I
z%12 is R
iPart(R/12 is J
J+I+R is O
Take away 7 until O is 6 or less
1 + X%4 is theta
L1 is 7,1,16,10
L1(theta) is D //DD location in string
DD is Str3 //determined by D and O
Determine LY is L
L1 and L2 are DD dates for each year
Add DD dates depending on L
Month lengths are L3
Get month and day
Determine whether to work backwards or forwards from DD is C
S is DD of month
Location of DD in str0 is R
Loop:
...Check if DD is the date looping
Increment date by C (+-1)
Add C to O (Started as 0; just counts)
Change O if OOB...
Display Str0 + 3 times O (Days away from DD)



Got that?!?!? Yeah, me neither. I got the method from here, and it's a pretty simplistic way to do it, involving quite a bit of modulo. I really can't do much to explain the rest of my... code... since I wrote it a while ago and I don't really ever do commented code, ever.
Pretty much, I guess, I store the DoomsDay (DD) dates in two lists, months in one, days in the other; this can be altered slightly if the year is a leap year. It calculates DD for that year using the method in the above website. From there, when you input a month and day, it calculates the closest DD date, and counts how many days of the week away it is from DD, then adds that to your inputted date.

There ya go!
Shock How long did it take to type all that up? Great article, do you plan on majoring in Mathematics?
Ivoah wrote:
Shock How long did it take to type all that up?


Haha, not too long. It was just me figuring out what I did, so it wasn't too bad!

Ivoah wrote:
Great article, do you plan on majoring in Mathematics?


Well, I am planning on a double major in CS and Applied Mathematics. Hopefully. If I don't die from the work and stuff.
GTemples27 wrote:
Ivoah wrote:
Shock How long did it take to type all that up?


Haha, not too long. It was just me figuring out what I did, so it wasn't too bad!

Ivoah wrote:
Great article, do you plan on majoring in Mathematics?


Well, I am planning on a double major in CS and Applied Mathematics. Hopefully. If I don't die from the work and stuff.


I'm thinking he was asking JWinslow23 Razz
pimathbrainiac wrote:
GTemples27 wrote:
Ivoah wrote:
Shock How long did it take to type all that up?


Haha, not too long. It was just me figuring out what I did, so it wasn't too bad!

Ivoah wrote:
Great article, do you plan on majoring in Mathematics?


Well, I am planning on a double major in CS and Applied Mathematics. Hopefully. If I don't die from the work and stuff.


I'm thinking he was asking JWinslow23 Razz


Psh, naaah. My post was way better than that one guy - his name is like JWinnie the Pooh or something - could ever hope for! Razz
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement