Most years have 52 weeks, some have 53, according to ISO8601.



Task

Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.




BEGIN
 
COMMENT
  FIND ISO CALENDAR YEARS HAVING 53 WEEKS. THE SIMPLEST
  TEST IS THAT A GIVEN YEAR WILL BE "LONG" IF EITHER THE
  FIRST OR LAST DAY IS A THURSDAY;
 
% CALCULATE P MOD Q %
INTEGER FUNCTION MOD(P, Q);
INTEGER P, Q;
BEGIN
   MOD := P - Q * (P / Q);
END;
 
COMMENT
  RETURN DAY OF WEEK (SUN=0, MON=1, ETC.) FOR A GIVEN
  GREGORIAN CALENDAR DATE USING ZELLER'S CONGRUENCE;
INTEGER FUNCTION DAYOFWEEK(MO, DA, YR);
INTEGER MO, DA, YR;
BEGIN
  INTEGER Y, C, Z;
  IF MO < 3 THEN
    BEGIN
      MO := MO + 10;
      YR := YR - 1;
    END
  ELSE MO := MO - 2;
  Y := MOD(YR, 100);
  C := YR / 100;
  Z := (26 * MO - 2) / 10;
  Z := Z + DA + Y + (Y / 4) + (C /4) - 2 * C + 777;
  DAYOFWEEK := MOD(Z, 7);
END;
 
% RETURN 1 IF YEAR IS LONG, OTHERWISE 0 %
INTEGER FUNCTION ISLONGYEAR(YR);
INTEGER YR;
BEGIN
  INTEGER THURSDAY;
  THURSDAY := 4;
  IF (DAYOFWEEK(1,1,YR) = THURSDAY) OR 
     (DAYOFWEEK(12,31,YR) = THURSDAY) THEN
       ISLONGYEAR := 1
  ELSE
       ISLONGYEAR := 0;
END;
 
% MAIN PROGRAM STARTS HERE %
INTEGER YEAR;
WRITE("ISO YEARS THAT WILL BE LONG IN THIS CENTURY:");
WRITE("");
FOR YEAR := 2000 STEP 1 UNTIL 2099 DO
  BEGIN
    IF ISLONGYEAR(YEAR) = 1 THEN WRITEON(YEAR);
  END;
 
END
 