How to resolve the algorithm Day of the week step by step in the Prolog programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Day of the week step by step in the Prolog 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 Prolog programming language
Source code in the prolog programming language
main() :-
christmas_days_falling_on_sunday(2011, 2121, SundayList),
writeln(SundayList).
christmas_days_falling_on_sunday(StartYear, EndYear, SundayList) :-
numlist(StartYear, EndYear, YearRangeList),
include(is_christmas_day_a_sunday, YearRangeList, SundayList).
is_christmas_day_a_sunday(Year) :-
Date = date(Year, 12, 25),
day_of_the_week(Date, DayOfTheWeek),
DayOfTheWeek == 7.
You may also check:How to resolve the algorithm Binary digits step by step in the SkookumScript programming language
You may also check:How to resolve the algorithm Count in octal step by step in the NewLISP programming language
You may also check:How to resolve the algorithm Roots of a quadratic function step by step in the Forth programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the AngelScript programming language
You may also check:How to resolve the algorithm Quine step by step in the OCaml programming language