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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Day of the week step by step in the AWK 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 AWK programming language

Source code in the awk programming language

# syntax: GAWK -f DAY_OF_THE_WEEK.AWK
# runtime does not support years > 2037 on my 32-bit Windows XP O/S
BEGIN {
    for (i=2008; i<=2121; i++) {
      x = strftime("%Y/%m/%d %a",mktime(sprintf("%d 12 25 0 0 0",i)))
      if (x ~ /Sun/) { print(x) }
    }
}


  

You may also check:How to resolve the algorithm Tau function step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Polynomial regression step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm HTTPS/Authenticated step by step in the Tcl programming language
You may also check:How to resolve the algorithm Maximum triangle path sum step by step in the Python programming language
You may also check:How to resolve the algorithm Call an object method step by step in the D programming language