cool date calculation thing

NERD ALERT, NERD ALERT!

Alright, so, you can calculate the day of the week for any given day, month, and year as follows:

    k = day
    m = month + 1 (see note)
    y = (m <= 10) ? year : year-1
    d = y % 100
    c = y / 100 

f = (k + (((13*m) - 1) / 5).floor + d + (d/4).floor + (c/4).floor - (2*c)) % 7

 m = 3: March, 4: April, …, 13: January, 14 February. (Basically we pop Jan/Feb to the end. because February likes to screw us over.)

Using this you can quickly find out things like, which months of a given year have Five Fridays, Saturdays, and Sundays. (e.g: October 2010.)

What’s really interesting though is that if you look at the corresponding months (http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week#Corresponding_months

The corresponding months ALSO has five fridays, saturdays, and sundays.

So, for instance, January 2010 ALSO has five fri sat and sundays.
(Or 1999, or 1954, or 2004, or 2010, or the next occurrence in 2021, etc.)

Ain’t that somethin? This holds true for any corresponding months where the first of the month falls on a friday.

Sadly, no months correspond with August, my birth month. So I wrote this loop to check which months just-so-happened to correspond with August for 1900-2300, here’s the algorithm and results:

Interestingly enough, August corresponds with February, but only on leap years! 

august had fivefrisatsuns in 1902!

august had fivefrisatsuns in 1913!

august had fivefrisatsuns in 1919!

august had fivefrisatsuns in 1924!

february had fivefrisatsuns in 1924!

august had fivefrisatsuns in 1930!

august had fivefrisatsuns in 1941!

august had fivefrisatsuns in 1947!

august had fivefrisatsuns in 1952!

february had fivefrisatsuns in 1952!

august had fivefrisatsuns in 1958!

august had fivefrisatsuns in 1969!

august had fivefrisatsuns in 1975!

august had fivefrisatsuns in 1980!

february had fivefrisatsuns in 1980!

august had fivefrisatsuns in 1986!

august had fivefrisatsuns in 1997!

august had fivefrisatsuns in 2003!

august had fivefrisatsuns in 2008!

february had fivefrisatsuns in 2008!

august had fivefrisatsuns in 2014!

august had fivefrisatsuns in 2025!

august had fivefrisatsuns in 2031!

august had fivefrisatsuns in 2036!

february had fivefrisatsuns in 2036!

august had fivefrisatsuns in 2042!

august had fivefrisatsuns in 2053!

august had fivefrisatsuns in 2059!

august had fivefrisatsuns in 2064!

february had fivefrisatsuns in 2064!

august had fivefrisatsuns in 2070!

august had fivefrisatsuns in 2081!

august had fivefrisatsuns in 2087!

august had fivefrisatsuns in 2092!

february had fivefrisatsuns in 2092!

august had fivefrisatsuns in 2098!

august had fivefrisatsuns in 2104!

february had fivefrisatsuns in 2104!

august had fivefrisatsuns in 2110!

august had fivefrisatsuns in 2121!

august had fivefrisatsuns in 2127!

august had fivefrisatsuns in 2132!

february had fivefrisatsuns in 2132!

august had fivefrisatsuns in 2138!

august had fivefrisatsuns in 2149!

august had fivefrisatsuns in 2155!

august had fivefrisatsuns in 2160!

february had fivefrisatsuns in 2160!

august had fivefrisatsuns in 2166!

august had fivefrisatsuns in 2177!

august had fivefrisatsuns in 2183!

august had fivefrisatsuns in 2188!

february had fivefrisatsuns in 2188!

august had fivefrisatsuns in 2194!

august had fivefrisatsuns in 2200!

august had fivefrisatsuns in 2206!

august had fivefrisatsuns in 2217!

august had fivefrisatsuns in 2223!

august had fivefrisatsuns in 2228!

february had fivefrisatsuns in 2228!

august had fivefrisatsuns in 2234!

august had fivefrisatsuns in 2245!

august had fivefrisatsuns in 2251!

august had fivefrisatsuns in 2256!

february had fivefrisatsuns in 2256!

august had fivefrisatsuns in 2262!

august had fivefrisatsuns in 2273!

august had fivefrisatsuns in 2279!

august had fivefrisatsuns in 2284!

february had fivefrisatsuns in 2284!

august had fivefrisatsuns in 2290!

Algorithm:

http://pastie.org/2690921

Aww yeh.

Short URL for this post: http://tmblr.co/ZP7OEyAdoUrc