Re: Number of days in a month
- From: Guybrush Threepwood <spambak@xxxxxxxxxxx>
- Date: Wed, 11 Jan 2006 15:00:47 +0000
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
.
- Prev by Date: Re: strange behaviuor
- Next by Date: Re: for loop in prolog
- Previous by thread: comparison predicates
- Next by thread: Permutations on lists
- Index(es):
Relevant Pages
|
|