prolog predicates
- From: repairman2003@xxxxxxxxx
- Date: 31 Jan 2006 12:16:06 -0800
This should be an easy question. I'm writing this predicate:
high_card(Hand, Card) is true iff
Hand is a list of length > 0 containing any
of the terms: ace, king, queen, jack,
and Card is the term in Hand that has the
highest value (ace > king > queen > jack).
Test cases:
?- high_card([ace], C).
C=ace.
?- high_card([ace, jack, jack], C).
C=ace.
?- high_card([queen, jack, king, jack], C).
C=king.
?- high_card([jack, queen], C).
C=queen.
I've got this so far:
high_card([],C):-
C=none.
high_card([ace|Y],C):-
C=ace.
high_card([X|ace],C):-
C=ace.
With this I'm not sure how to check for the end of the list for an ace
and if one exists set C to = ace but if not then C = king:
high_card([king|Y],C):-
high_card(Y,D),
C=king.
Any help is greatly appriciated.
.
- Follow-Ups:
- Re: prolog predicates
- From: Markus Triska
- Re: prolog predicates
- Prev by Date: Re: problem: how to translate predicate logic sentences to Prolog?
- Next by Date: Re: prolog predicates
- Previous by thread: problem: how to translate predicate logic sentences to Prolog?
- Next by thread: Re: prolog predicates
- Index(es):
Relevant Pages
|
|