Re: Number of days in a month



On Sat, 31 Dec 2005 10:59:19 +0100, Bart Demoen wrote:

> 2) the query ?- number_of_days(Month,Days,1996). has only two answers,
> while one might expect 12. You can group the clauses for february as
> follows:
>
> number_of_days(february, D, Year):-
> (leapyear(Year) ->
> D = 29
> ;
> D = 28
> ).

I've got another question regarding this topic. I now have:

month_name(1,january).
month_name(2,february).
month_name(3,march).
% etc.


number_of_days(_, january, 31).
number_of_days(Year, february, D):-
(leap_year(Year) ->
D = 29
;
D = 28
).
number_of_days(_, march, 31).
% etc.


Now, I sometimes want to know the number of days, but I only have the
monthnumber. What I do know is:

number_of_days_by_number(Year, MonthNumber, NumberOfDays):-
month_name(MonthNumber, MonthName),
number_of_days(Year, MonthName, NumberOfDays).

Would it be a more Prolog way if I use the same predicate
number_of_days in some way?

number_of_days(_, MonthNumber, Days):-
month_name(MonthNumber, MonthName),
number_of_days(Year, MonthName, NumberOfDays).

But naturally, this gives me always 2 answers per month.

?- number_of_days(2005, Month, 31).

Month = januari
Month = 1

etc.


Which one is the best solution?

--
"Don't worry about people stealing your ideas. If your ideas are any
good, you'll have to ram them down people's throats."
-- Howard Aiken

.



Relevant Pages

  • Re: VB or VC++?
    ... LOL -- Let us guess what that would be. ... You just go right ahead and ram it down some throats. ... Prev by Date: ...
    (comp.programming)
  • Re: Struts link tag
    ... you'll have to ram them down people's throats." ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Re: question concerning evaluate.
    ... > you have two consecutive WHEN clauses of a EVALUATE, like below, the ... > For some reason I thought there would be an implied "and" between the ... > two when statements but I can find no basis for this assumption. ... Prev by Date: ...
    (comp.lang.cobol)
  • Re: Why is Howard lying about Sirius?
    ... I am sure there were no clauses in ... > contract that forbid him to do so. ... Prev by Date: ...
    (alt.fan.howard-stern)
  • Re: Greg Dolan RCC member and ebay seller has died
    ... Reversing the two clauses would ... be much more insulting. ... Craig ... Prev by Date: ...
    (alt.marketing.online.ebay)