/* Easter calculation in Picat. Easter can be between March 22 and April 25. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. main => go. go => Years = (400..100..2000) ++ [2100] ++ 2010..2030, foreach(Year in Years) println(Year=easter(Year)) end, nl. % % Minimum or maximum easter, i.e. years where the Easter is % at the extrema dates, March 22 and April 25. % go2 => Map = get_global_map(), Map.put("minimal",0), Map.put("maximal",0), foreach(Year in 0..9999) [Year,Month,Day,_Dow] = easter(Year), Type = _, if Month == 3, Day == 22 then Type := "minimal" elseif Month == 4, Day == 25 then Type := "maximal" end, if nonvar(Type) then Map.put(Type,Map.get(Type)+1), printf("%04d-%02d-%02d is %s Easter\n", Year, Month, Day, Type) end end, println(Map), nl. % Calculates Gregorian Easter easter(Year) = Easter => A = Year mod 19, B = Year div 100, C = Year mod 100, D = B div 4, E = B mod 4, F = (B + 8) div 25, G = (B - F + 1) div 3, H = (19 * A + B - D - G + 15) mod 30, I = C div 4, K = C mod 4, L = (32 + 2 * E + 2 * I - H - K) mod 7, M = (A + 11 * H + 22 * L) div 451, N = H + L - 7 * M + 114, % Year, Month, Day, DayOfWeek=1 (Sun) Easter = [Year, N div 31, (N mod 31) + 1, 1].