/***********************************************************************

 Day of Week:

 The result is an integer in the range 0-6, 
   where 0=Monday and 6=Sunday  (for the Zeller formular)

 Reference:
 - Chr. Zeller;
   Kalender-Formeln, Acta Mathematica, 9 (1887) 131-136

 - The Day of the Week for Gregorian Calendars (A. D. Bradley) ?? 82-87

 - A. Grassl;
   Kalenderrechnung: Wochentage im laufenden Jahr.
   (Calendar calculations: Days of the week in a year.)
   MNU. Der Mathematische und Naturwissenschaftliche Unterricht. 
   (Apr 1997) v. 50(3) p. 150-151.

 - Keith & Craver;
   The ultimate perpetual calendar?, JoRM 22:4 (1990) 280-282
   day of the week as a 44 character expression in C. (illegal use of --)
   The following 45 character C expression by Keith is correct.
   dow(y,m,d) { return (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7; }

 - M. Oswalden;
   Wochentag und Osterdatum - im Kopf gerechnet.
   T. 1.  Gregorianischer Kalender (ab 15. Okt. 1582)
   T. 2.  Julianischer Kalender.
   Wiss. Nachr. (Jan 1990) (no.82) p. 41-44
   Wiss. Nachr. (Apr 1990) (no.83) p. 40-42.
   ZblD 1992h.00756 + 1992h.00760 

 - A. W. Butkewitsch, M. S. Selikson; 
   Ewige Kalender, Teubner (Leipzig) 1974
   Kleine Naturwissenschaftliche Bibliothek, Bd. 23, p98-113

 - Heinz Bachmann; 
   Kalenderarithmetik, 2nd Ed.,
   Juris Verlag, Z"urich, 1984, ISBN 3-260-05035-0, p26-42
-----------------------------------------------------------------------
   mailto:Torsten.Sillke@uni-bielefeld.de    1999-03-15
***********************************************************************/

int dayofweek(int day, int month, int year)
{
   /** Zeller's congruence for the Gregorian calendar. **/
   /** With 0=Monday, ... 5=Saturday, 6=Sunday         **/
   if (month < 3) {
      month += 12;
      year--;
   }
   return ((13*month+3)/5 + day + year + year/4 - year/100 + year/400) % 7;
}


int dayofweek0(int d, int m, int y)
{
   /** a 45 character C expression by Keith    **/
   /** With 0=Sunday, 1=Monday, ... 6=Saturday **/
   return (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7;
}


int dayofweek1(int day, int month, int year)
{
   /** Variation of Sillke for the Gregorian calendar. **/
   /** With 0=Sunday, 1=Monday, ... 6=Saturday         **/
   if ((month -= 2) <= 0) {
      month += 12;
      year--;
   }
   return (83*month/32 + day + year + year/4 - year/100 + year/400) % 7;
}



int main ()
{
   int m;
   for (m=1;m<=12;m++)
     printf("%3d %3d %3d\n", 
	dayofweek(0,m,0), 
	dayofweek0(0,m,0), 
	dayofweek1(0,m,0) );
   return 0;
}

