Code Comments
Programming Forum and web based access to our favorite programming groups.In some countries (particularly the Scandinavian ones) it is traditional to solve puzzles/problems (= nuts) at Easter time. Here's one which might be of interest to some readers. The earliest possible (Gregorian) Easter Sunday falls this year (2008). In what next 10 years does this recur again? Please feel free to display the code/link of the Prolog program used to compute these years. ;-) -- Mail sent to this email address is deleted unread on the server. Please send replies to the newsgroup.
Post Follow-up to this messageOn Mar 23, 6:38 am, "Nameless" <news.m...@getmail.no> wrote: > In some countries (particularly the Scandinavian ones) it > is traditional to solve puzzles/problems (= nuts) at Easter > time. Here's one which might be of interest to some readers. > > The earliest possible (Gregorian) Easter Sunday falls this > year (2008). In what next 10 years does this recur again? > Please feel free to display the code/link of the Prolog > program used to compute these years. ;-) > > -- > Mail sent to this email address is deleted unread > on the server. Please send replies to the newsgroup. Easter, as determined by the ecclesiastical rules of Western Christianity, is the first Sunday after the first full moon on or after March 21st (the vernal equinox for purposes of this rule). The earliest possible date for Easter in the Western church is therefore March 22nd, and we came close this year without attaining that limit. It seems to me the difficulty of determining the dates of the full moons outweigh any interest in how Prolog might be used to encode the logic of this definition. Perhaps an astronomy newsgroup would be more suitable for this "nut"? regards, chip
Post Follow-up to this messageOn Mar 23, 2:28 pm, Chip Eastham <hardm...@gmail.com> wrote: > On Mar 23, 6:38 am, "Nameless" <news.m...@getmail.no> wrote: > > > > > Easter, as determined by the ecclesiastical rules > of Western Christianity, is the first Sunday after > the first full moon on or after March 21st (the > vernal equinox for purposes of this rule). The > earliest possible date for Easter in the Western > church is therefore March 22nd, and we came close > this year without attaining that limit. > > It seems to me the difficulty of determining the > dates of the full moons outweigh any interest in > how Prolog might be used to encode the logic of > this definition. Perhaps an astronomy newsgroup > would be more suitable for this "nut"? > > regards, chip Here's a nice site if someone wants to look into the details of the "ecclesiastical full moon": http://users.sa.chariot.net.au/~gmarts/easter.htm If we're only checking the next 10 years, then of course a lookup table for these dates is not all that tedious. regards, chip
Post Follow-up to this messageChip Eastham wrote: > On Mar 23, 6:38 am, "Nameless" <news.m...@getmail.no> wrote: > > Easter, as determined by the ecclesiastical rules > of Western Christianity, is the first Sunday after > the first full moon on or after March 21st (the > vernal equinox for purposes of this rule). The > earliest possible date for Easter in the Western > church is therefore March 22nd, and we came close > this year without attaining that limit. > > It seems to me the difficulty of determining the > dates of the full moons outweigh any interest in > how Prolog might be used to encode the logic of > this definition. Perhaps an astronomy newsgroup > would be more suitable for this "nut"? Indeed, computing the exact date is quite boring, but I think Chip was asking to show how easy it is to compute (an approximate??) date in Prolog. This is my ECLiPSe code for computing the Easter date. It uses the definition of Easter (1st Sunday after full moon after 21st of March). It does not work _always_ (due to approximations, I think), but it does in the requested years (2008-2018) Cheers, Marco /* Computes the Easter date given the year (2 digits) ?- easter(08,Easter), convert(Easter,Day,Month,Year). Found a solution with cost 3005 Easter = 3005 // it is the 3005th day after 1 Jan 2000 Day = 23 Month = 3 Year = 8 Yes (0.00s cpu) */ :- lib(ic). :- lib(branch_and_bound). easter(Year,Easter):- in_year(Easter,Year), %define domain equinox(Year,Equinox), Easter $> Equinox, is_sunday(Easter,X1), FullMoon $> Equinox, full_moon(FullMoon,X2), Easter $>= FullMoon, minimize( labeling([Easter,X1,X2]) ,Easter). in_year(Day,Year):- Jan1 $= Year * 365.25, % Approximation: a year lasts 365 days and a quarter (for leap years) Dec31 $= (Year+1) * 365.25-1, integers(Day), Day :: Jan1..Dec31. equinox(Year,Equinox):- nleap(Year,NL), Equinox $= Year*365+31+28+21+NL. is_sunday(Date,N):- integers(N), Date $= N*7+2. %2nd of Jan 2000 is Sunday full_moon(Date,N):- integers(N), Date $= N*29.53 +21. %21st of Jan 2000 is Full Moon %============== Boring stuff ================= convert(Date,Day,Month,Year):- convert(Date,Day,1,0,Month,Year). convert(Date,Day,MonthIn,YearIn,MonthOut ,YearOut):- days(MonthIn,DaysMonth,YearIn), Date=<DaysMonth,!, Day=Date,MonthIn=MonthOut,YearIn=YearOut . convert(Date,Day,MonthIn,YearIn,MonthOut ,YearOut):- days(MonthIn,DaysMonth,YearIn), Date>DaysMonth,!, (MonthIn=12 -> MonthTemp =1, YearTemp is YearIn+1 ; MonthTemp is MonthIn+1, YearTemp=YearIn), DateTemp is Date-DaysMonth, convert(DateTemp,Day,MonthTemp,YearTemp, MonthOut,YearOut). % Days of the month days(1,31,_). days(2,D,Year):- (leap(Year) -> D=29 ; D=28). days(3,31,_). days(4,30,_). days(5,31,_). days(6,30,_). days(7,31,_). days(8,31,_). days(9,30,_). days(10,31,_). days(11,30,_). days(12,31,_). leap(Year):- Year mod 4 =:= 0. % Simplification.... nleap(Year,NL):- NL is fix(Year /4)+1. -- http://www.ing.unife.it/docenti/MarcoGavanelli/
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.