How to resolve the algorithm Day of the week step by step in the Scheme programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Day of the week step by step in the Scheme 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 Scheme programming language
Source code in the scheme programming language
(define (day-of-week year month day)
(if (< month 3)
(begin (set! month (+ month 12)) (set! year (- year 1))))
(+ 1
(remainder (+ 5 day (quotient (* (+ 1 month) 13) 5)
year (quotient year 4) (* (quotient year 100) 6) (quotient year 400))
7)))
(define (task)
(let loop ((y 2121) (v '()))
(if (< y 2008)
v
(loop (- y 1)
(if (= 7 (day-of-week y 12 25))
(cons y v)
v)))))
(task)
; (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 Web scraping step by step in the VBA programming language
You may also check:How to resolve the algorithm Simple windowed application step by step in the Go programming language
You may also check:How to resolve the algorithm Sockets step by step in the Racket programming language
You may also check:How to resolve the algorithm String length step by step in the Objeck programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Rust programming language