<?xml version="1.0" encoding="UTF-8" ?>
  <resource>
  <id>7062</id>
  <path>/www/nrich/html/content/id/7062/</path>
  <resourceTypeID>1</resourceTypeID>
  <last_published>2011-06-07T16:03:23</last_published>
  <indexXML>&lt;mdoxml version=&quot;1.0&quot;&gt;
  &lt;br /&gt;
  &lt;ul id=&quot;buttonBar&quot;&gt;
    &lt;li&gt;
      &lt;a href=&quot;http://nrich.maths.org/5928&amp;amp;part=&quot;&gt;Warm-up
problem&lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;a href=&quot;http://nrich.maths.org/304&amp;amp;part=&quot;&gt;Try this next&lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;a href=&quot;https://nrich.maths.org/discus/messages/27/27.html?1307454058&quot;&gt;
Ask NRICH&lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;a href=&quot;http://nrich.maths.org/6070&amp;amp;part=&quot;&gt;Read all about
it&lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;a href=&quot;http://nrich.maths.org/6488&amp;amp;part=solution&quot;&gt;Last week's
solution&lt;/a&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  &lt;div&gt;
    &lt;br /&gt;
Zeller worked out a formula to calculate the day of the week for
any date.&lt;br /&gt;
$$&lt;br /&gt;
d= \left(n+\mbox{int}\left[\frac{(m+1)\times
26}{10}\right]+y+\mbox{int}\left[\frac{y}{4}\right]+\mbox{int}\left[\frac{C}{4}\right]-2C\right)\mbox{mod
}7&lt;br /&gt;
$$&lt;br /&gt;
This formula contains a lots of symbols and terminology, as
follows:&lt;br /&gt;
    &lt;br /&gt;
In Zeller's formula $d$ stands for the day of the week, numbered
$0$ to $6$ for Saturday - Friday.&lt;br /&gt;
    &lt;br /&gt;
$n$ is the day of the month, numbered 1 to 28, 29, 30 or 31
depending on the month in question.&lt;br /&gt;
    &lt;br /&gt;
$m$ is the month, numbered from $3-12$ for March - December; $m=13$
in January and $m=14$ in February.&lt;br /&gt;
    &lt;br /&gt;
$y$ is the last two digits of the year, or the last two digits of
the previous year if $m=13$ or $14$.&lt;br /&gt;
    &lt;br /&gt;
$C$ is the first two digits of the year.&lt;br /&gt;
    &lt;br /&gt;
'int[$x$]' is a function which rounds $x$ down to the nearest
integer or returns $x$ if $x$ is already an integer.&lt;br /&gt;
    &lt;br /&gt;
'mod 7' means return the remainder when divided by 7.&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
There are two parts to your task:&lt;br /&gt;
    &lt;br /&gt;
1) Check that you can use the formula to work out the day of the
week for a few dates.&lt;br /&gt;
    &lt;br /&gt;
2) (Difficult extension) Work out why it is, either roughly or
exactly, that Zeller's algorithm works. A spreadsheet might help to
work out why each term is present in the algorithm.&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
  &lt;/div&gt;
  &lt;div class=&quot;framework&quot;&gt;
    &lt;span style=&quot;font-style: italic;&quot;&gt;Did you
know ... ?&lt;/span&gt;
    &lt;br /&gt;
    &lt;br /&gt;
Date algorithms are complicated by leap years, when there are 29
days in February. Leap years occur roughly every 4 years, although
on occasions a leap year is skipped. The precise rule for
determining leap years is as follows:&lt;br /&gt;
    &lt;br /&gt;
If the&amp;#160;year modulo 400 is 0 then it is a leap year; else if
the year modulo 100 is 0 then it is not a leap year;&amp;#160; else if
the&amp;#160;year modulo 4 is 0 then it is a leap year; else it is not
a leap year.&lt;br /&gt;
    &lt;br /&gt;
Some human calculators are able to run Zeller's algorithm in their
heads. Can you learn how to do this? You can see an awesome human
calculator in action on &lt;a href=&quot;http://www.youtube.com/watch?v=dtotrboSUqQ&quot;&gt;You
Tube&lt;/a&gt;.&lt;/div&gt;
  &lt;br /&gt;
&lt;/mdoxml&gt;
</indexXML>
  <solutionXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;
&lt;p&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;This solution is not &amp;#39;complete&amp;#39;, but does indicate why the formula works. It will make more sense if you test it out using a spreadsheet&lt;/span&gt;.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
This tasks seems daunting at first but then you might realise that essentially the function is a &amp;#39;counter&amp;#39; and the year starts at 1st March and ends on 28/9th of February.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
Years are always of the same structure with the exception of the last day of Feb:&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
From  1st March to 1st April is +31 days. &lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
From 1st April to 1st May is +30 days.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
From 1st May to 1st June is +31 days.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
etc.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
For weekday calculations we are only interested in mod 7 changes. Since 31 is 3 mod 7 and 30 is 2 mod 7 we have the following differences between the first of the months, with the +0/1 corresponding to February.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
(1Mar) +3, &lt;span style=&quot;font-weight: bold;&quot;&gt;+2&lt;/span&gt;, +3, &lt;span style=&quot;font-weight: bold;&quot;&gt;+2&lt;/span&gt;, +3, +3, &lt;span style=&quot;font-weight: bold;&quot;&gt;+2&lt;/span&gt;, +3, &lt;span style=&quot;font-weight: bold;&quot;&gt;+2&lt;/span&gt;, +3, +3,&lt;span style=&quot;font-weight: bold;&quot;&gt;+0/1&lt;/span&gt; (1Mar)&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
 Accumulating the changes from the 1st March (mod 7) gives&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
(1Mar) 0&lt;br&gt;&lt;/br&gt;
(1Apr) 3&lt;br&gt;&lt;/br&gt;
(1May) 5&lt;br&gt;&lt;/br&gt;
(1Jun) 1&lt;br&gt;&lt;/br&gt;
(1Jul) 3&lt;br&gt;&lt;/br&gt;
(1Aug) 6&lt;br&gt;&lt;/br&gt;
(1Sep) 2&lt;br&gt;&lt;/br&gt;
(1Oct) 4&lt;br&gt;&lt;/br&gt;
(1Nov) 0&lt;br&gt;&lt;/br&gt;
(1Dec) 2&lt;br&gt;&lt;/br&gt;
(1Jan) 5&lt;br&gt;&lt;/br&gt;
(1Feb) 1&lt;br&gt;&lt;/br&gt;
(1Mar) 1 or 2 in a leap year&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
Interestingly, the $\mbox{int}\left[\frac{(m+1)\times 26}{10}\right]$ part matches these offsets with the labellings of months given  (try it out to see).&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
So, in the absence of leap years the expression would work.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
The part $y+\mbox{int}\left[\frac{y}{4}\right]+\mbox{int}\left[\frac{C}{4}\right]-2C$ has the correct mod 7 behaviour to count the leap years (try it).&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
 &lt;/p&gt;

&lt;/mdoxml&gt;</solutionXML>
  <noteXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;&lt;br&gt;&lt;/br&gt;&lt;/mdoxml&gt;</noteXML>
  <clueXML/>
  <canonXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;mdoxml version=&quot;1.0&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;This solution is not complete,
but does indicate why the formula works. It will make more sense if
you test it out using a spreadsheet&lt;/span&gt;.&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
This tasks seems daunting at first but then you might realise that
essentially the function is a 'counter' and the year starts at 1st
March and ends on 28/9th of February.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
Years are always of the same structure with the exception of the
last day of Feb:&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
From  1st March to 1st April is +31 days. &lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
From 1st April to 1st May is +30 days.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
From 1st May to 1st June is +31 days.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
etc.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
For weekday calculations we are only interested in mod 7 changes.
Since 31 is 3 mod 7 and 30 is 2 mod 7 we have the following
differences between the first of the months, with the +0/1
corresponding to February.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
(1Mar) +3, &lt;span style=&quot;font-weight: bold;&quot;&gt;+2&lt;/span&gt;, +3, &lt;span style=&quot;font-weight: bold;&quot;&gt;+2&lt;/span&gt;, +3, +3, &lt;span style=&quot;font-weight: bold;&quot;&gt;+2&lt;/span&gt;, +3, &lt;span style=&quot;font-weight: bold;&quot;&gt;+2&lt;/span&gt;, +3, +3,&lt;span style=&quot;font-weight: bold;&quot;&gt;+0/1&lt;/span&gt; (1Mar)&lt;br&gt;&lt;/br&gt;
&lt;br&gt;&lt;/br&gt;
 Accumulating the changes from the 1st March (mod 7)
gives&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
(1Mar) 0&lt;br&gt;&lt;/br&gt;
(1Apr) 3&lt;br&gt;&lt;/br&gt;
(1May) 5&lt;br&gt;&lt;/br&gt;
(1Jun) 1&lt;br&gt;&lt;/br&gt;
(1Jul) 3&lt;br&gt;&lt;/br&gt;
(1Aug) 6&lt;br&gt;&lt;/br&gt;
(1Sep) 2&lt;br&gt;&lt;/br&gt;
(1Oct) 4&lt;br&gt;&lt;/br&gt;
(1Nov) 0&lt;br&gt;&lt;/br&gt;
(1Dec) 2&lt;br&gt;&lt;/br&gt;
(1Jan) 5&lt;br&gt;&lt;/br&gt;
(1Feb) 1&lt;br&gt;&lt;/br&gt;
(1Mar) 1 or 2 in a leap year&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
Interestingly, the $\mbox{int}\left[\frac{(m+1)\times
26}{10}\right]$ part matches these offsets with the labellings of
months given  (try it out to see).&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
So, in the absence of leap years the expression would work.&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
The part
$y+\mbox{int}\left[\frac{y}{4}\right]+\mbox{int}\left[\frac{C}{4}\right]-2C$
has the correct mod 7 behaviour to count the leap years (try it).
&lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;
 &lt;br&gt;&lt;/br&gt;&lt;/mdoxml&gt;</canonXML>
  <end_user_role>2</end_user_role>
  <difficulty>4</difficulty>
  <keystage1>0</keystage1>
  <keystage2>0</keystage2>
  <keystage3>0</keystage3>
  <keystage4>0</keystage4>
  <keystage4plus>1</keystage4plus>
  <title>Weekly Challenge 41: Happy \birthDay</title>
  <description>A weekly challenge concerning the interpretation of an algorithm to
determine the day on which you were born.</description>
  <spec_group>Decision Mathematics and Combinatorics
    <specifier>Algorithms</specifier>
  </spec_group>
  <spec_group>Numbers and the Number System
    <specifier>Modulus arithmetic</specifier>
  </spec_group>
  <spec_group>Collections
    <specifier>Weekly Challenge</specifier>
  </spec_group>
</resource>