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


 
/* NetRexx ************************************************************
* 30.08.2012 Walter Pachl derived from Rexx version 3
*                         omitting dead code left there
**********************************************************************/
options replace format comments java crossref savelog symbols
Numeric digits 20
nr5fwe=0
years_without_5fwe=0
mnl='Jan Mar May Jul Aug Oct Dec'
ml='1 3 5 7 8 10 12'
Loop j=1900 To 2100
  year_has_5fwe=0
  Loop mi=1 To ml.words()
    m=ml.word(mi)
    jd=greg2jul(j,m,1)
    IF jd//7=4 Then Do                 /* 1st m j is a Friday */
      nr5fwe=nr5fwe+1
      year_has_5fwe=1
      If j<=1905 | 2095<=j Then
        Say mnl.word(mi) j 'has 5 full weekends'
      End
    End
    If j=1905 Then Say '...'
    if year_has_5fwe=0 Then years_without_5fwe=years_without_5fwe+1
  End
Say ' '
Say nr5fwe 'occurrences of 5 full weekends in a month'
Say years_without_5fwe 'years without 5 full weekends'
exit
 
method greg2jul(yy,mm,d) public static returns Rexx
/***********************************************************************
* Converts a Gregorian date to the corresponding Julian day number
* 19891101 Walter Pachl REXXified algorithm published in CACM
*                (Fliegel & vanFlandern, CACM Vol.11 No.10 October 1968)
***********************************************************************/
  numeric digits 12
/***********************************************************************
* The published formula:
* res=d-32075+1461*(yy+4800+(mm-14)%12)%4+,
*     367*(mm-2-((mm-14)%12)*12)%12-3*((yy+4900+(mm-14)%12)%100)%4
***********************************************************************/
  mma=(mm-14)%12
  yya=yy+4800+mma
  result=d-32075+1461*yya%4+367*(mm-2-mma*12)%12-3*((yya+100)%100)%4
    Return result                   /* return the result              */