How to resolve the algorithm Day of the week step by step in the Tcl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Day of the week step by step in the Tcl programming language

Table of Contents

Problem Statement

A company decides that whenever Xmas falls on a Sunday they will give their workers all extra paid holidays so that, together with any public holidays, workers will not have to work the following week (between the 25th of December and the first of January).

In what years between 2008 and 2121 will the 25th of December be a Sunday? Using any standard date handling libraries of your programming language; compare the dates calculated with the output of other languages to discover any anomalies in the handling of dates which may be due to, for example, overflow in types used to represent dates/times similar to   y2k   type problems.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Day of the week step by step in the Tcl programming language

Source code in the tcl programming language

package require Tcl 8.5

for {set y 2008} {$y <= 2121} {incr y} {
    if {[clock format [clock scan "$y-12-25" -format {%Y-%m-%d}] -format %w] == 0} {
        puts "xmas $y is a sunday"
    }
}

  

You may also check:How to resolve the algorithm Determine if a string has all unique characters step by step in the C++ programming language
You may also check:How to resolve the algorithm String matching step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the PDP-11 Assembly programming language
You may also check:How to resolve the algorithm Arbitrary-precision integers (included) step by step in the REXX programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the LiveCode programming language