How to resolve the algorithm Day of the week step by step in the Arc programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Day of the week step by step in the Arc 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 Arc programming language
Source code in the arc programming language
(= day-names '(Sunday Monday Tuesday Wednesday Thursday Friday Saturday))
(= get-weekday-num (fn (year month day)
(= helper '(0 3 2 5 0 3 5 1 4 6 2 4))
(if (< month 3) (= year (- year 1)))
(mod (+ year (helper (- month 1)) day
(apply + (map [trunc (/ year _)] '(4 -100 400))))
7)))
(= get-weekday-name (fn (weekday-num) (day-names weekday-num)))
(up i 2008 2121
(when (is 0 (get-weekday-num i 12 25))
(prn i)))
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
You may also check:How to resolve the algorithm Compare a list of strings step by step in the S-lang programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the LiveCode programming language
You may also check:How to resolve the algorithm Case-sensitivity of identifiers step by step in the PHP programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the DWScript programming language
You may also check:How to resolve the algorithm Tree from nesting levels step by step in the OxygenBasic programming language