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

Published on 12 May 2024 09:40 PM

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

Source code in the red programming language

Red []
repeat yy 114 [
  d: to-date reduce [25 12 (2007 + yy )]
  if 7 = d/weekday [ print d ] ;; 7 = sunday
]
;; or
print "version 2"

d: to-date [25 12 2008]
while [d <= 25/12/2121 ] [
  if 7 = d/weekday [ 
    print rejoin [d/day '. d/month '. d/year ] 
  ] 
  d/year: d/year + 1
]

  

You may also check:How to resolve the algorithm First-class functions step by step in the GAP programming language
You may also check:How to resolve the algorithm Split a character string based on change of character step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Multi-dimensional array step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the Swift programming language
You may also check:How to resolve the algorithm Teacup rim text step by step in the AutoHotkey programming language