Studies - The formula for calculating the day of the week.

ZX Review #7-8-9-10
(C) Jessica Justice, g.Kolpashevo


   In the ZX-Revue N1-2/97 section
"Etudes" Basil has announced a competition
the procedure of the calendar. I know the perfect formula for 
calculating the day of the week. Formula taken from the book 
"Problems in Programming" (authors - SA Abramov, GG Gnezdilova 
and others, the series' library of programming, " ed. "Science" 
1988), and its authors refer to "Computer programs

that work! "(authors Lee J.D.,
Beech G., Lee T.D.). Thus, the formula: it is believed that the 
year is in range from 1582 to 4902. Then the day of the week 
(0-Sunday 1-Monday, ... 6-Saturday) is the remainder of the 
division 7 value of the expression:



  [2.6m-0.2] + d + y + [y / 4] + [c / 4]-2c

where d - the day of the month (1 ...
31), m - number of months per year
(The numbering starts in March,
ie 1-March 2-April ... 10 December, January and February are 
months with the numbers 11 and 12 previous year); c - top two 
digits of the year (15 ... 49); y - lower digits of the year 
(00 ... 99); [X] - denotes the integer part.



   On the BASIC program can
look like this:

10 INPUT "day =", day
20 INPUT "month =", month
30 INPUT "year =", year
40 IF month <3 THEN LET month = month +12:

   LET year = year-1: REM If the January or

   February, it will last months of the previous
   previous year
50 LET month = month-2:

   REM Numbering starts from March
60 LET y $ = STR $ year
70 LET c = VAL (y $ (1 TO 2)):

   REM The first two digits of the year
80 LET y = VAL (y $ (2 TO 4)):

   REM The second two digits of year
90 LET value = INT (2.6 * month-02) + day + y + INT

   (Y / 4) + INT (c / 4) -2 * c
100 LET week = value-7 * (INT (value / 7)):

    REM week - Modulo

    expression of seven and is the number

    day of the week
110 PRINT "Day of week -"; week


   As a result, the screen get the weekday (0 .. 6).


   To help make it all the native will have to turn
to aid calculator. Alas, I do not
so good to know a calculator, perhaps someone from the readers 
of the Revue will be able to perform this algorithm in assembly 
language? 


           *