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

Published on 12 May 2024 09:40 PM

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

Source code in the lua programming language

require("date")

for year=2008,2121 do
   if date(year, 12, 25):getweekday() == 1 then
      print(year)
   end
end


local dTab = {day = 25, month = 12}
for year = 2008, 2121 do
    dTab.year = year
    if os.date("%A", os.time(dTab)) == "Sunday" then
        print(year)
    end
end


  

You may also check:How to resolve the algorithm Hello world/Text step by step in the MEL programming language
You may also check:How to resolve the algorithm Strip block comments step by step in the Groovy programming language
You may also check:How to resolve the algorithm Pragmatic directives step by step in the Delphi programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the IS-BASIC programming language
You may also check:How to resolve the algorithm Fibonacci word step by step in the Lua programming language