For Programmers: Free Programming Magazines  


Home > Archive > Prolog > February 2005 > urgent help needed









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author urgent help needed
rockshu

2005-02-24, 3:58 am

Here is the file we are given..

Family.pl

female(ann).
female(cathy).
female(lisa).
female(lora).
female(mary).
female(rose).
female(susan).

male(charles).
male(david).
male(fred).
male(george).
male(ian).
male(joe).
male(john).
male(paul).
male(peter).

mother_of(john,ann).
mother_of(mary,ann).
mother_of(cathy,ann).
mother_of(peter,mary).
mother_of(paul,mary).
mother_of(charles,cathy).
mother_of(susan,cathy).
mother_of(george,lora).
mother_of(ian,lora).
mother_of(lisa,rose).

father_of(john,fred).
father_of(mary,fred).
father_of(cathy,fred).
father_of(peter,joe).
father_of(paul,joe).
father_of(charles,david).
father_of(susan,david).
father_of(george,paul).
father_of(ian,paul).
father_of(lisa,charles).


1)define a predicate ladies/0 that tells how many females are there in
the database.
(expected behavious)
? ladies.
there are seven women in the database.
yes


2) define predicate for the following expected behaviour.
? grandfather_of(grandchild,ann).
grandchild = peter;
granchild = paul;
grandchild = charles;
grandchild = susan ;
No

? cousin_of(peter,C).
C = charles;
c = susan ;
No

? Cousins_of(peter,L).
L= [charles,susan]
yes


3) define a predicate sublist/2 for testing whether the list in the
first argument is a sublistof the second one:
? sublist ([5,6,7],[1,2,3,4,5,6,7,8,9]).
yes
?- sublist ([5,66,7],[1,2,3,4,5,6,7,8,9]).
No
it should also return on backtracking all sublists of alist given
inthe second argument.
?- sublist(S,[1,2,3,4])
S = [];
s=[1];
s=[1,2];
etc ans similarly till s=[];
no

i would be highly obliged if somebody helps me in solving these
problems as i am trying ot solve them from the last 25 days!!

:cry: :cry: :(


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jan Wielemaker

2005-02-24, 8:58 am

On 2005-02-24, rockshu <indiewolf@yahoo-dot-com.no-spam.invalid> wrote:

<snipped assignment>

> i would be highly obliged if somebody helps me in solving these
> problems as i am trying ot solve them from the last 25 days!!


.... And you have nothing to show us explaining your progress and where
you're stuck. Interesting. Even 25 minutes of googling will find the
answers to many of these problems. I suggest the Logo language :-)

--- Jan
rockshu

2005-02-25, 4:00 pm

> Jan Wielemakerwrote:
On 2005-02-24, rockshu
<indiewolf@yahoo-dot-com.no-spam.invalid> wrote:
>
> <snipped assignment>
>
> i would be highly obliged if somebody helps me in solving these
> problems as i am trying ot solve them from the last 25 days!!
>

.... And you have nothing to show us explaining your progress and
where
you're stuck. Interesting. Even 25 minutes of googling will find
the
answers to many of these problems. I suggest the Logo language :-)

--- Jan[/quote:50648cbc1e]


well well well...so u want to see my progress..
buddy googling didnt help..otherwise i wud not have posted in the
forums!!
now the progress part..
for the first question...i used bagof/setof to list all the
females..and i knwo th eoutput wud be using "write"and "length" but
how?? how will i get the desired output??

in the second question i have defined predicate for parent,sibling and
even cousin but i am not getting the required answer both in the case
of cousin_of and Grandfather_of!!

i have solved the part (a) of the third question but the backtracking
part is yet to be solved.for the backtracking part i am using
is_front/2 predicate and wiht the help of sublist/2 i hope i can do
it sing recursion..but how ??..i am really ...
ihope this satisfies u that i am genuinely in a mess...SO PLEASE HELP
ME OUT!!


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Georgios Tagalakis

2005-02-26, 8:57 am

> now the progress part..
> for the first question...i used bagof/setof to list all the
> females..and i knwo th eoutput wud be using "write"and "length" but
> how?? how will i get the desired output??


link what you have with something like:

length(List_Of_All_Females,Num_Fems),
write (Num_Fems), write (' females in the db').

> in the second question i have defined predicate for parent,sibling and
> even cousin but i am not getting the required answer both in the case
> of cousin_of and Grandfather_of!!


What did you do exactly? Post code

> i have solved the part (a) of the third question but the backtracking
> part is yet to be solved.for the backtracking part i am using
> is_front/2 predicate and wiht the help of sublist/2 i hope i can do
> it sing recursion..but how ??..i am really ...


sublist(List, List).
sublist(Sub, [Head|Tail]) :-
sublist2(Tail, Head, Sub).

sublist2(Sub, _, Sub).
sublist2([Head|Tail], _, Sub) :-
sublist2(Tail, Head, Sub).
sublist2([Head|Tail], X, [X|Sub]) :-
sublist2(Tail, Head, Sub).

> ihope this satisfies u that i am genuinely in a mess...SO PLEASE HELP
> ME OUT!!


Hope that helps

--- Georgios Tagalakis


rockshu

2005-02-26, 3:58 pm

first of all thank u for replying !! i managed to solve the first
question!!
still stuck with second and third!!


> in the second question i have defined predicate for parent,sibling

and
> even cousin but i am not getting the required answer both in the

case
> of cousin_of and Grandfather_of!!
>
>
> What did you do exactly? Post code



parent(X,Y) :- father_of(X,Y).
parent(X,Y) :- mother_of(X,Y).

grandfather_of(X,G) :- parent(X,P), father(P,G).


grandfather_of(X,G) :- father_of(X,P), father_of(P,G).
grandfather_of(X,G) :- mother_of(X,P), father_of(P,G).

child(C, P) :- parent(P, C).

grandchild(_,Z) :- child(Z,_),child(_,Z).

sister(X,S) :- female(S), parent(S,P), parent(X,P), X \== S.

brother(X,S) :- male(S), parent(S,P), parent(X,P), X \== S.

aunt(X,A) :- parent(X,P), sister(P,A).
uncle(X,U) :- parent(X,P), brother(P,U).


cousin(X,C) :- (aunt(X,P) ; uncle(X,P)), parent(C,P).


i used the above predicates...but cant get the answers!!
kindly help


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
rockshu

2005-02-26, 3:58 pm

> i have solved the part (a) of the third question but the
backtracking
> part is yet to be solved.for the backtracking part i am using
> is_front/2 predicate and wiht the help of sublist/2 i hope i can do
> it sing recursion..but how ??..i am really ...
>
>
> sublist(List, List).
> sublist(Sub, [Head|Tail]) :-
> sublist2(Tail, Head, Sub).
>
> sublist2(Sub, _, Sub).
> sublist2([Head|Tail], _, Sub) :-
> sublist2(Tail, Head, Sub).
> sublist2([Head|Tail], X, [X|Sub]) :-
> sublist2(Tail, Head, Sub).



i tired ur code along with
my_member(X,[X|_]).
my_member(X,[_|Y]) :- my_member(X,Y).

but got the following answer!! but the answer desired is somethign
liek in my first post!!


sublist(S,[1,2,3,4]).

S = [1, 2, 3, 4] ;

S = [2, 3, 4] ;

S = [3, 4] ;

S = [4] ;

S = [] ;

S = [3] ;

S = [2, 4] ;

S = [2] ;

S = [2, 3] ;

S = [1, 3, 4] ;

S = [1, 4] ;

S = [1] ;

S = [1, 3] ;

S = [1, 2, 4] ;

S = [1, 2] ;

S = [1, 2, 3] ;

No


kindly help !!
thank u!


Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com