How to resolve the algorithm Day of the week step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Day of the week step by step in the REXX 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 REXX programming language
Source code in the rexx programming language
do year=2008 to 2121
if date('w', year"1225", 's') == 'Sunday' then say year
end /*year*/
do year=2008 to 2121
if date('b', year"1225", 's') // 7 == 6 then say year
end /*year*/
/*REXX program displays in which years 12/25 (December 25th) falls on a Sunday. */
parse arg start finish . /*get the START and FINISH years. */
if start=='' | start=="," then start=2008 /*Not specified? Then use the default.*/
if finish=='' | finish=="," then finish=2121 /* " " " " " " */
do y=start to finish /*process all the years specified. */
if date('Weekday', y"-12-25", 'ISO')\=='Sunday' then iterate
/* if date('w' , y"-12-25", 'i' ) ··· (same as above). */
/* ↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑ ↑↑↑ */
/* option yyyy-mm-dd fmt */
say 'December 25th,' y "falls on a Sunday."
end /*y*/
/*stick a fork in it, we're all done. */
/*REXX program (old school) displays in which years 12/25 (Dec. 25th) falls on a Sunday.*/
parse arg start finish . /*get the START and FINISH years. */
if start=='' | start=="," then start=2008 /*Not specified? Then use the default.*/
if finish=='' | finish=="," then finish=2121 /* " " " " " " */
do y=start to finish /*process all the years specified. */
if dow(12,25,y)==1 then say 'December 25th,' y "falls on a Sunday."
end /*y*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
dow: procedure; parse arg m,d,y; if m<3 then do; m= m+12; y= y-1; end
yL= left(y, 2); yr= right(y, 2); w= (d + (m+1)*26%10 +yr +yr%4 +yL%4 +5*yL) //7
if w==0 then w= 7; return w /*Sunday=1, Monday=2, ··· Saturday=7*/
You may also check:How to resolve the algorithm DNS query step by step in the C# programming language
You may also check:How to resolve the algorithm Determine if a string is numeric step by step in the CFScript programming language
You may also check:How to resolve the algorithm Truth table step by step in the Perl programming language
You may also check:How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the Erlang programming language
You may also check:How to resolve the algorithm Perfect shuffle step by step in the C# programming language