#!/usr/bin/ruby

#
## http://rosettacode.org/wiki/Five_weekends
#

require('DateTime');

var happymonths = [];
var workhardyears = [];
var longmonths = [1, 3, 5, 7, 8, 10, 12];

range(1900, 2100).each { |year|
   var countmonths = 0;
   longmonths.each { |month|
        var dt = %s'DateTime'.new(
            year => year,
            month => month,
            day   => 1
        );

        if (dt.day_of_week == 5) {
            countmonths++;
            var yearfound = dt.year;
            var monthfound = dt.month_name;
            happymonths.append(join("  ", yearfound, monthfound));
      }
   }

    if (countmonths == 0) {
        workhardyears.append(year);
    }
}

say "There are #{happymonths.len} months with 5 full weekends!";
say "The first 5 and the last 5 of them are:";
say happymonths.ft(0, 4).join("\n");
say happymonths.ft(-5,-1).join("\n");
say "No long weekends in the following #{workhardyears.len} years:";
say workhardyears.join(",");
