Correspondent

Charles in NJ


Host ID: 229
website:
email: catintp.nospam@nospam.yahoo.com
episodes: 3

1240 - Doomsday Rule | 2013-05-03

HPR Episode: Doomsday Perpetual Calendar Method

What is it?  http://en.wikipedia.org/wiki/Doomsday_rule  
  (due to John H. Conway, a mathematician born in Liverpool)

  * He's done other research that hackers might like to check out.  
  * Look up the "Game of Life" and "cellular automata".  
  * There may be episodes on these topics, but those should come
      with visualization software.

John H. Conway
  http://en.wikipedia.org/wiki/John_Horton_Conway

Game of Life
  http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
  

Doomsday Rule lets you find the day of the week for any date
  * Dates in history, in immediate past or in future are all good.
  * Works for both the Gregorian and Julian calendar.  
    - I'll only be looking at Gregorian dates for now.
    - Method should work well for dates from 1800 onward.
    - If dates for non-Gregorian calendars are converted to their
        (extrapolated) Gregorian equivalents, this method works.

Wikipedia entry (includes recent optimization):
  http://en.wikipedia.org/wiki/Doomsday_algorithm


Why do this?  It came up in Episode Zero of my "N Days" show on 
calendar counting, where I used it without explanation.

  http://hackerpublicradio.org/eps.php?id=1143


Demos: Check these answers at www.day-calculator.com  
  * Some listeners may now adjourn to the latest Linux Outlaws episode.


Method: Get Century Anchor Day, calculate offset for the year to find
   Doomsday's reference location for current year, find closest 
   reference date to target date, and count off to the answer.

a) Isaac Newton's date of birth: 
   - 25 December 1642 - 1600's Tuesday. 
     Year 42 = 3*12 + 6 and (6/4) = 1. 
     Hence 3 + 6 + 1 = 10 for an offset of 3.
     Tuesday + 3 = Friday.  12/12 is Friday, so 12/26 is Friday
     Newton was born 12/25, so that was a Thursday

b) My grandfather's date of birth:
   - 20 January 1898 - 1800's anchor is Friday.  
     Year 98 = 8*12 + 2, (2/4) = 0.  
     So 8 + 2 + 0 = 10 gives an offset of 3.

   - 1898 wasn't a leap year, so 10 January was Monday 
   - That means 17 January was a Monday, too.
   - So 20 January 1898 was a Thursday.

c) A wedding anniversary that I like to remember: 15 May 2000
   - 2000 has anchor day on Tuesday, and no offset.
   - Rule: "I work 9 to 5 at 7-11", so 9 May (16 May) are on Tuesday.
   - 15 May 2000 was a Monday.  True.  'Twas the day after Mother's Day.
   
d) My parent's wedding day: 19 May 1957
   - 1900 has anchor day Wednesday.  57 = 4*12 + 9 and (9/4) = 2. 
   - So 4 + 9 + 2 = 15 or an offset of 1.
   - 9 May is Thursday, as is 16 May.  The 19th is 3 days later.
   - So 19 May 1957 was a Sunday.


Plan: I'm going to reveal the magic behind this, and introduce some 
mental shortcuts to help you learn to do this in your head.  

If you can master the 12's row in your times tables up to 8 times 12, 
and the 4's row up the 20s or 30s, and you can tell time on a 12-hour 
clock, you should be able to do this.  

We're not in school, so paper and pencil to track the numbers, and 
finger-counting offsets to days of the week are all allowed. 


Explanation:
1. Certain memorable dates fall on the same day of the week as
   "Doomsday" = last day of February, whatever that is.

2. Dates recycle every 400 years, and Doomsday Anchor dates by Century
   are 1600: Tuesday, 1700: Sunday, 1800: Friday, 1900: Wednesday.

3. That's enough, but to simplify mental math notice 12-year cycles.
   - Every completed 12 years pushes the days of the week ahead by +1
   - Each year within the current incomplete cycle adds +1
   - Each leap year in current cycle adds +1 (including current year) 

4. Doomsday dates are:
   a. January 10 and Doomsday (last day of February)
   
   b. Odd months: Add +4 through July, then subtract 4.
      7 March, 9 May, 11 July
      5 September, 7 November
   
   c. Even months are reflexive: 4/4, 6/6, 8/8, 10/10, 12/12


See the attached spreadsheets for examples and annotated calculations.

 - LibreOffice Calc: 229-Charles-in-NJ-Doomsday-Rule-v1.ods
 
 - Excel 5/95 'xls' for LibreOffice or Gnumeric:
     229-Charles-in-NJ-Doomsday-Rule.xls
 
 - Gnumeric: 229-Charles-in-NJ-Doomsday-Rule-v1.gnumeric


Bonus Content:
 - Excel VBA module: 229-Charles-in-NJ-Doomsday-Rule.vbaxl.bas 
     * Import the .bas module
     * Input is an Excel "Date" object
     * Very proprietary formats and code, but some people use it.
 
 - Python:  doomsday.py
     * Contains two functions:  Each returns a string value for the day
          of the week, e.g., "Sunday"
       
       dayOfWeek(year, month, day): Doomsday is last day of February,
          and the (month, day) are converted to relative ordinal dates.
          For leap years, we have to push both Doomsday and any target
          date after 28 February up by one for the leap day.
       
       dayOfWeek2(year, month, day): Doomsday date anchors are computed
           for each month, so leap years require adjustments to the
           anchors for January and February to account for the shift
           in the February ending date.  Later months are fine.

 - Script for GNU 'bc': doomsday.bc is a bc 'port' of the Python code
     * Differences: Return value is a number from 0-6 that represents
         the day of the week by its relative position.
         
       0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 
       4 = Thursday, 5 = Friday, 6 = Saturday
 
     * In a shell, run 'bc' with the filename as an argument:
       catintp@Derringer:~$  bc doomsday.bc
       
       - This loads the two functions in the file.  You can invoke them
           within 'bc' like any other function:
           
       dayofweek(1981, 5, 15)
       dayofweek2(1642, 12, 25)
       dayofweek(2013, 11, 22)
       dayofweek2(2059, 5, 19)

 - Alternate Script for GNU 'bc': doomsday2.bc 
     * Return value is still a number from 0-6 that represents
         the day of the week by its relative position.
     
     * Uses a side effect to print a human-friendly answer.   
     
     * English only, but localisation should be easy.

Links


1189 - Part One: Counting Partridges and Gold Rings | 2013-02-21

Edited version - re sent

The Sonar Project has $9,838 raised with 256 people contributing. A big thanks to all the !HPR Listeners who helped out.
It's not too late to contribute to the ACF. See http://accessiblecomputingfoundation.org/ for more information.

Tomorrow The Eleventh Annual Southern California Linux Expo starts. Running from February 22 to the 24, 2013 in the Hilton Los Angeles International Airport. Speakers include Kyle Rankin, Joe Brockmeier and Matthew Garrett.
See http://www.socallinuxexpo.org/scale11x for more information

The N Days of Christmas? Intro to Recreational Math Part One: Counting Partridges and Gold Rings

The complete shownotes can be found here:

Pascal's Triangle:

Background on Pascal's Triangle and the Binomial Theorem, see the excellent videos by Sal Khan at http://KhanAcademy.org

Contact: Charles in NJ Email: catintp@yahoo.com

Charlie + Alpha + Tango + India + November + Tango + Papa.


1143 - The N Days of Christmas? Intro to Recreational Math | 2012-12-19

Hacker Public Radio: 206 203 5729

The N Days of Christmas? Intro to Recreational Math
Part Zero: Calendar Counting

First episode of HPR that contains a direct discussion of a math topic.
 - Episode 479 Ohio Linux Fest, Klaatu interviews DWick about math 
      software for Linux
      
 - Episode 523 Using Petunia software to teach math


Inspired by a traditional song that is proof that some songs do not
   need to be recorded by William Shatner to be annoying.
 - Repetitive and formulaic
 - Involves a lot of counting, and that's our focus here. 
 
 
What is the 12 Days of Christmas?
 - Starts on Christmas Day, runs through the day before the next Season
 - Hint: That's 'Epiphany', which starts January 6.
 - Counting calendar days comes hard, so we tend to use our fingers
 - Turns out that using our fingers is quite mathematical. Here's why.
 
Finger Counting: How do I count Twelve Days?
 - Let's start easy, with the fingers on one hand. My hands have five.
 - To name the Five Days of New Years is easy: January 1-5 
 
 - What about the Five Days of Christmas?
        Physical way                   General way
   * Christmas Day gets 1 (thumb)     Dec 25 is one day after Dec 24
   * Dec 26 gets 2 (index)            26 - 24 = 2 days
   * Dec 27 gets 3 (salute finger)    27 - 24 = 3 days
   * Dec 28 gets 4 (ring)             28 - 24 = 4 days
   * Dec 29 gets 5 (pinky)            29 - 24 = 5 days
 
 - Notice that counting 5 days, starting with Dec 25, is the same
     as numbering the days after Dec 24 (Christmas Eve).
   * In math, we call this "1-1 correspondence with natural numbers"
   * Math can give you the same certainty as using your fingers.  
   * But it handles larger problems, because you don't run out.
 
 - Example: I'm booked to speak on Day 4 of a 5-day conference
   * Starts on the 25th of the month
   * When do I have to show up?
     - Wrong: Add 4 to first day (25), and arrive a day late.
     - Correct: Add 4 to date of pre-registration cocktail party (24),
          and arrive on time.
      
 - OK. Back to Twelve Days of Christmas.  
   * The labeling approach tells us that December can hold only the 
       first seven of the Twelve Days of Christmas, 
   * December 31 - December 24 gives me 7 days.
 
 
 Partitioning: Adding hands full of additional fingers as needed
  - How do we handle the case where we go into the next month?
  - Key insight: Running out of December days for the Twelve Days is 
       like running out of fingers on one hand when we count to 8.
  - We are so good at counting on our fingers that we don't recognize 
       the act of partitioning the number 8 between our two hands.
    *  Left hand gets 1, 2, 3, 4 and 5.
    *  Right hand picks up 6, 7 and 8 by mapping them to fingers 1,2,3.

  - To count even higher, we could:
      1) keep borrowing other people's hands, or
      2) track the number of times we reuse our two hands as we go
    
    * First method mirrors calendar math ("Annexing" hands, or months)
    * Second is positional notation ("base 10" and all that)


Back to the Twelve Days
 - I have Twelve Days: 1, 2, ... 12 to assign to dates, even though I 
     may only be interested in the first and last dates right now.
   * Start: How many can I fit into December?
   * December 31st is last. It gets assigned 31 - 24, or 7. 
   * By "finger math", that means I have mapped 7 of the Twelve Days
   * That leaves 12 - 7, or 5 days into January.
 
 - Who can tell me which days are assigned in January? Anyone?
   * That's right, Ken.  January 1, 2, 3, 4 and 5.
   * So the Twelve Days of Christmas runs 25 December to 5 January 


Question: What if there were 72 Days of Christmas?  When would it end?
 - Note: Don't worry.  This is purely hypothetical.

 - Let's attack this with finger math, with partitioning and annexing
   * December, as we have seen, accounts for 7 days: 25 through 31
   * That leaves 72 - 7, or 65 days
   * January easily picks up 31 days: 1 to 31, leaving 65 - 31 = 34 days
   * February can handle either 28 days, or 29 on a leap year.
   * This leaves us either 5 or 6 days into March

 - Final Answer: 72 Days of Christmas would run from Christmas until the
     following March 5 (leap year), or March 6 (all other years).
   * On Day 73, everyone would enter treatment for Christmas overdose.

Let's check the answer: Day 72 would end ten weeks and 2 days after 
   the opening cocktail party (Monday). So Day 72 should be Wednesday.
   * Next year is not a leap year, so last day is March 6.
   * By the Doomsday perpetual calendar method, Feb 28 is Thursday.
   
   Doomsday method: http://en.wikipedia.org/wiki/Doomsday_rule
   
   * So March 7 is Thursday, and March 6 is Wednesday.
   * It worked.
 
Why should I bother with Calendar Math?
 - I learn to look for ways to partition hard problems into easier ones.
 - I learn the same skills that I'll need to debug "off-by-one" errors
     and other boundary violations, which kill you in C programs.
 - I will never miss a speaking engagement, as long as I count my 
     Conference Days from the cocktail party, not from the Keynote.


Next episode: Part One
  Counting partridges and gold rings with Pascal
  - Warning: There will be two semi-magic formulas at the end.
  - I'll show you an easy way to do running sums in a spreadsheet.
  - You can skip the formulas, and I'll never know.
  - Since this is HPR, not school.  We can look up the formulas.


Contact: Charles in NJ
Email: catintp@yahoo.com

Charlie + Alpha + Tango + India + November + Tango + Papa.


Become a Correspondent












linkboxes

Sponsor:

Events:


Affiliates: