/*
Day of the week in Picat.
From
http://rosettacode.org/wiki/Day_of_the_week
"""
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.
"""
Model created by Hakan Kjellerstrand, hakank@gmail.com
See also my Picat page: http://www.hakank.org/picat/
*/
import cp.
main => go.
go =>
L = [Year : Year in 2008..2121, dow(Year, 12, 25) == 0],
println(L),
println(len=L.length),
nl.
%
% Day of week, Sakamoto's method
% http://en.wikipedia.org/wiki/Weekday_determination#Sakamoto.27s_Method
%
dow(Y, M, D) = R =>
T = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4],
if M < 3 then
Y := Y - 1
end,
R = (Y + Y // 4 - Y // 100 + Y // 400 + T[M] + D) mod 7.