The month of October in 2010 has five Fridays, five Saturdays, and five Sundays.



Task

 Write a program to show all months that have this same characteristic of five full weekends from the year 1900 through 2100 (Gregorian calendar). 
 Show the number of months with this property (there should be 201).
 Show at least the first and last five dates, in order.

Algorithm suggestions

 Count the number of Fridays, Saturdays, and Sundays in every month.
 Find all of the 31-day months that begin on Friday.

Extra credit

Count and/or show all of the years which do not have at least one five-weekend month (there should be 29).



Related tasks
 Day of the week
 Last Friday of each month
 Find last sunday of each month


include c:\cxpl\codes;                  \intrinsic 'code' declarations
 
 
func    WeekDay(Year, Month, Day);      \Return day of week (0=Sat 1=Sun..6=Fri)
int     Year, Month, Day;
[if Month<=2 then [Month:= Month+12;  Year:= Year-1];
return rem((Day + (Month+1)*26/10 + Year + Year/4 + Year/100*6 + Year/400) / 7);
];      \WeekDay
 
 
int     MonthTbl, Year, I, C;
[MonthTbl:= [1, 3, 5, 7, 8, 10, 12];            \months with 31 days
C:= 0;
for Year:= 1900 to 2100 do
  for I:= 0 to 6 do                             \for all the 31-day months...
    if WeekDay(Year, MonthTbl(I), 1) = 6 then   \first of month is a Friday
        [C:= C+1;                               \count this year
        if C<=5 or C>201-5 then                 \show first 5 and last 5 years
                [IntOut(0, Year);  ChOut(0, ^ );
                 IntOut(0, MonthTbl(I));  CrLf(0);
                ];
        ];
IntOut(0, C);  CrLf(0);                         \show number of years
 
\Count and show all years that don't have any 5-weekend months
C:= 0;
for Year:= 1900 to 2100 do
        [for I:= 0 to 6 do                      \for all the 31-day months...
            if WeekDay(Year, MonthTbl(I), 1) = 6 \Friday\ then
                I:= 10;                         \bail out of 'for' loop
        if I<10 then                            \'for' loop completed
                [if (C&$F) = 0 then CrLf(0);    \(format 16 years per line)
                C:= C+1;                        \ without finding a 5-weekend
                IntOut(0, Year);  ChOut(0, ^ ); \ so show the year
                ];
        ];
CrLf(0);  IntOut(0, C);  CrLf(0);               \show number of years
]