CodeWalrus

General => Other => Topic started by: JWinslow23 on December 20, 2015, 09:02:30 AM

Title: Today Is The Day After Doomsday
Post by: JWinslow23 on December 20, 2015, 09:02:30 AM
WARNING: The following post includes math concepts and calendar calculations that certainly are NOT for the faint of heart. :P
As well, at request of c4ooo, I have put the equivalent mathematical equations in spoilers below each method. Please don't hate me...I eat my cereal dryyyyyyyy (http://bit.ly/1RyCuXk) :P


No, not that kind of Doomsday :P

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 (https://en.wikipedia.org/wiki/The_World_Calendar) 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!
[spoiler=Give up?]It was Sunday.[/spoiler]
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:
(http://bit.ly/1NxcoA2)

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:
(http://bit.ly/1QAcQBF)

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:
(http://bit.ly/1S3dAOI)

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:
(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:
(http://bit.ly/1kbnwb5)
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)[1]:
: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 ;)

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 (http://sydney.edu.au/engineering/it/~kev/pp/TUTORIALS/1b/carroll.html) (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):
[spoiler=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.[/spoiler]
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:
[spoiler=Carrollian method](http://bit.ly/1kb5dCN)[/spoiler]

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 (https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life)[4]), 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:















MonthMemorable DoomsdaysMnemonics
January3 (common), 4 (leap)
10 (common), 11 (leap)
31 (common), "32" (leap)
the 3rd for 3 years, and the 4th every 4
repeated number (1/11) in leap years, 1 day before in common years
last day of January (but pretend January has 32 days in leap years)
February"0" (common), 1 (leap)
14 (common)
21 (common), 22 (leap)
28 (common), 29 (leap)
binary: is this year a leap year? (0=false, 1=true)
Valentine's Day
repeated number (2/22) in leap years, 1 day before in common years
last day of February
March"0"
14
last day of February (i.e. the day before March 1)
Pi Day ;)
April4repeated number (4/4)
May9"I work 9 to 5 at 7-11[5]"
June6repeated number (6/6)
July4
11
Independence Day (USA)
"I work 9 to 5 at 7-11[5]"
August8repeated number (8/8)
September5"I work 9 to 5 at 7-11[5]"
October10
31
repeated number (10/10)
Halloween
November7"I work 9 to 5 at 7-11[5]"
December12
26
repeated number (12/12)
Boxing Day (i.e. the day after Christmas Day)
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:
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:
[spoiler=Conway Doomsday method](http://bit.ly/1OhgSb4)[/spoiler]

"Odd+11"
Of course, there's always a better way :P , 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 (http://arxiv.org/ftp/arxiv/papers/1006/1006.3913.pdf) three (http://easydoomsday.blogspot.com/) times (http://arxiv.org/ftp/arxiv/papers/1010/1010.0765.pdf) to my knowledge, but one of the easiest methods, called the Odd+11 method, is described here:

Relevant formulae for Odd+11 Doomsday method:
[spoiler=Odd+11 Doomsday method](http://bit.ly/22j2vO7)[/spoiler]




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]: I actually wrote this code back in November 2013! Wow, I guess this "obsession" of mine is old :P
[2]: 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).
[3]: 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. :P
[4]: You lost the game.
/me runs :P
[5]: 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.
[6]: 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.
[7]: 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.
Title: Re: Today Is The Day After Doomsday
Post by: Snektron on December 20, 2015, 10:09:44 AM
That's a lot of math :P You probaly could do something with the amount of days in a year too (no, not 365 or 366, but 365.242199)
Title: Re: Today Is The Day After Doomsday
Post by: JWinslow23 on December 20, 2015, 10:20:58 AM
Well, that would certainly get you closer towards an astronomical calendar :P . We're concerned with our own at the moment though.

And sure, that's a lot of math, but it's really not so hard to do. The simplest way I've shown is nothing more than a lookup in a table, some addition and division by 2, and counting off days.
Title: Re: Today Is The Day After Doomsday
Post by: alexgt on December 20, 2015, 02:42:55 PM
O.O nice I personally don'y believe in dooms day but I do believe in math, thanks for teaching me a few things ;)
Title: Re: Today Is The Day After Doomsday
Post by: c4ooo on December 20, 2015, 07:17:23 PM
Wait what... you where born Jan 23, 2001? O.O
:w00t: :w00t: :w00t: :w00t: :w00t: :w00t: :w00t: :w00t:

About the vowel thing, does that mean that this only works in english? :P
Title: Re: Today Is The Day After Doomsday
Post by: JWinslow23 on December 20, 2015, 08:06:33 PM
Quote from: alexgt on December 20, 2015, 02:42:55 PM
O.O nice I personally don'y believe in dooms day but I do believe in math, thanks for teaching me a few things ;)
It's not that kind of Doomsday (according to Conway, "anchor day" would have been more appropriate), but you're welcome.
Quote from: c4ooo on December 20, 2015, 07:17:23 PM
Wait what... you where born Jan 23, 2001? O.O
:w00t: :w00t: :w00t: :w00t: :w00t: :w00t: :w00t: :w00t:

About the vowel thing, does that mean that this only works in english? :P
Yes, I was born in 2001. My 15th birthday is coming up in a month and 3 days.

Also, that was just a way for Dodgson (Carroll) to describe the month table...without using a table. What the table really is is this:




MonthJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember
Month "value"0315990120151181212243273304334

which is the number of days in that year that passed before the start of that month (with February counting as 28 days). This is equivalent to Dodgson's list in mod 7 (which is all that matters, because adding or subtracting 1 week doesn't change the result).




MonthJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember
Dodgson's month "value"03363643423303112

Remember this in whatever pattern you want. You can also use this completely-reduced table for reference, knowing that adding or subtracting 7 has no effect on the "correctness" of the value:




MonthJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember
Reduced month "value"033614625035
Title: Re: Today Is The Day After Doomsday
Post by: JWinslow23 on December 21, 2015, 01:56:28 AM
Bump.

I have added purely mathematical methods, for those interested. I even gave some TI-BASIC code I wrote over 2 years ago! Times really haven't changed :P
Title: Re: Today Is The Day After Doomsday
Post by: alexgt on December 21, 2015, 02:14:10 AM
Cool ;), and pun intended?! :P
Title: Re: Today Is The Day After Doomsday
Post by: Araidia on December 21, 2015, 05:18:39 AM
Thought you guys were talking about the December 21 2012 doomsday scare...
Title: Re: Today Is The Day After Doomsday
Post by: JWinslow23 on December 21, 2015, 06:40:50 AM
Quote from: alexgt on December 21, 2015, 02:14:10 AM
Cool ;), and pun intended?! :P
Pun not intended. It was Julian accident ;)

Quote from: Araidia on December 21, 2015, 05:18:39 AM
Thought you guys were talking about the December 21 2012 doomsday scare...

As I said in the beginning of the post, it's not that kind of Doomsday :P The timing almost couldn't have been more perfect, though, in hindsight. The Doomsday on December 19 isn't too far off from December 21...hmmm :-|
Title: Re: Today Is The Day After Doomsday
Post by: Yuki on December 21, 2015, 06:44:40 AM
Quote from: JWinslow23 on December 21, 2015, 06:40:50 AM
Quote from: alexgt on December 21, 2015, 02:14:10 AM
Cool ;), and pun intended?! :P
Pun not intended. It was Julian accident ;)
Are you guys talking about me?
Title: Re: Today Is The Day After Doomsday
Post by: JWinslow23 on December 21, 2015, 06:46:48 AM
Quote from: Juju on December 21, 2015, 06:44:40 AM
Quote from: JWinslow23 on December 21, 2015, 06:40:50 AM
Quote from: alexgt on December 21, 2015, 02:14:10 AM
Cool ;), and pun intended?! :P
Pun not intended. It was Julian accident ;)
Are you guys talking about me?
Julian -> "truly an". That specific pun was intended. What, your real name is Julian?

In that case, I have some exciting news...there's an obsolete calendar system named after you! :P
Title: Re: Today Is The Day After Doomsday
Post by: Yuki on December 21, 2015, 06:50:39 AM
It's Julien, actually. Which is French for Julian, which is in turn English for Latin name Julius. A famous bearer of the name is Julius Caesar, for which the Julian calendar and the month of July has been named for.
Title: Re: Today Is The Day After Doomsday
Post by: JWinslow23 on December 21, 2015, 06:56:10 AM
Quote from: Juju on December 21, 2015, 06:50:39 AM
It's Julien, actually. Which is French for Julian, which is in turn English for Latin name Julius. A famous bearer of the name is Julius Caesar, for which the Julian calendar and the month of July has been named for.
Oh. Your name is Julien. Now Juju makes sense :P

And I knew that Julius Caesar was the namesake of the calendar system and July. Just like August was named after Augustus Caesar. And September through December were named because they used to be the 7th through 10th months (and the names stuck :P ). I just like to have fun with people. :P
Title: Re: Today Is The Day After Doomsday
Post by: c4ooo on December 21, 2015, 04:06:03 PM
Welp, and there i was pronouncing Juju's name wrong :P
(since latin has no 'J' or 'K' Julius Caesar was spelled "Iulius Caesar" and pronounced 'Yulias Kayzar")
Title: Re: Today Is The Day After Doomsday
Post by: alexgt on December 21, 2015, 10:33:39 PM
Quote from: c4ooo on December 21, 2015, 04:06:03 PM
Welp, and there i was pronouncing Juju's name wrong :P
(since latin has no 'J' or 'K' Julius Caesar was spelled "Iulius Caesar" and pronounced 'Yulias Kayzar")
Cool history O.O
Title: Re: Today Is The Day After Doomsday
Post by: JWinslow23 on December 21, 2015, 11:23:44 PM
Anyways, can someone do the challenge of finding the day of the week of their birthday with any of the methods above? I want other people to learn what I have learned! Math is fun when shared with other people ;)
Title: Re: Today Is The Day After Doomsday
Post by: Yuki on December 22, 2015, 12:08:56 AM
1900s anchor day: Wednesday
91+11=102
102/2=51
51+11=62
62%7=6
7-6=1
Doomsday 1991 = Wednesday+1=Thursday
Closest Doomsday: 8/8 is a Thursday
+1 week = 8/15
Thursday+5 days=Tuesday

Therefore, my birthday was a Tuesday. Using the same logic, this year it will fall on a Saturday.
Title: Re: Today Is The Day After Doomsday
Post by: JWinslow23 on December 22, 2015, 06:31:22 AM
Quote from: Juju on December 22, 2015, 12:08:56 AM
1900s anchor day: Wednesday
91+11=102
102/2=51
51+11=62
62%7=6
7-6=1
Doomsday 1991 = Wednesday+1=Thursday
Closest Doomsday: 8/8 is a Thursday
+1 week = 8/15
Thursday+5 days=Tuesday

Therefore, my birthday was a Tuesday. Using the same logic, this year it will fall on a Saturday.
Awesome. Checking with other methods, and on WolframAlpha to triple-check, 8/20/1991 was in fact a Tuesday. :)