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


  [ over 3 < if [ 1 - ]
    dup 4 / over +
    over 100 / -
    swap 400 / +
    swap 1 - 
    [ table 
      0 3 2 5 0 3
      5 1 4 6 2 4 ]
    + + 7 mod ]                     is dayofweek ( day month year --> weekday )
 
  [ 1 - 
    [ table 
      $ "January"   $ "February"
      $ "March"     $ "April" 
      $ "May"       $ "June"
      $ "July"      $ "August"
      $ "September" $ "October"
      $ "November"  $ "December" ]
    do ]                            is monthname (   monthnumber --> $        )
 
  [] [] temp put
  201 times
    [ true temp put
      i^ 1900 +
      ' [ 1 3 5 7 8 10 12 ]
      witheach
        [ 2dup swap 
          1 unrot dayofweek
          5 = iff
            [ false temp replace
              over join nested
              swap dip join ]
          else drop ]
      temp take iff
        [ temp take 
          swap join
          temp put ]
      else drop ]
  temp take swap
  say "There are " 
  dup size echo 
  say " months with five weekends."
  cr cr
  5 split swap 
  say "Five weekends: "
  witheach 
    [ do swap 
      monthname echo$ 
      sp echo 
      i if say ", " ]
  cr say "               ..."
  cr space 15 of echo$
  -5 split nip
  witheach 
    [ do swap 
      monthname echo$ 
      sp echo 
      i if say ", " ]
  cr cr
  say "Years without five weekends: " 
  witheach 
    [ echo 
      i if say ", "
      i^ 8 mod 7 = if
        [ cr space 29 of echo$ ] ]