How to resolve the algorithm Five weekends step by step in the Sidef programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Five weekends step by step in the Sidef programming language

Table of Contents

Problem Statement

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

Algorithm suggestions

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

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Five weekends step by step in the Sidef programming language

Source code in the sidef programming language

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.first(5).join("\n");
say happymonths.last(5).join("\n");
say "No long weekends in the following #{workhardyears.len} years:";
say workhardyears.join(",");


  

You may also check:How to resolve the algorithm DNS query step by step in the Frink programming language
You may also check:How to resolve the algorithm Abundant odd numbers step by step in the MAD programming language
You may also check:How to resolve the algorithm Determine if a string has all the same characters step by step in the Sidef programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the RPL programming language
You may also check:How to resolve the algorithm Descending primes step by step in the Phix programming language