hw9 - (a) Write a predicate reverse(X,Y) that is true if...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Suggested Homework #9 Suggested Homework #9 (for Quiz #9 on 12/6/06) Problem 1. Recall the following prolog predicate described in class: parent(kim,holly). parent(margaret,kim). parent(herbert,margaret). parent(john,kim). parent(felix,john). parent(albert,felix). In addition, suppose we define the following predicates: male(herbert). male(john). male(felix). male(albert). female(kim). female(holly). female(margaret). (a) Write a predicate sibling(X,Y) that is true if X is a sibling of Y . (b) Write a predicate uncle(X,Y) that is true if X is an uncle of Y . (c) Write a predicate niece(X,Y) that is true if Y is a niece of X . (d) Write a predicate first_cousin(X,Y) that is true if X and Y are first cousins (i.e. they have parents who are siblings). (e) Write a predicate cousin(X,Y) that is true if X and Y are cousins (i.e. including first, second, third etc. cousins). Problem 2. List manipulation
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (a) Write a predicate reverse(X,Y) that is true if the list Y is the reverse of the list X . (b) Write a predicate sum(L,N) that is true if the number N is the sum of the numbers in the list L . http://www.cs.ucsd.edu/classes/fa06/cse130/shw/shw9.html (1 of 2) [2/13/2008 5:27:40 PM] Suggested Homework #9 (c) Write a predicate max(L,N) that is true if the number N is the largest (maximum) of the numbers in the list L . (d) Write a predicate sorted(L) that is true if the list L is sorted in increasing order. (e) Write a predicate subsequence(L1,L2) that is true if the list L2 is a subsequence of the list L1 . For example: subsequence([1,2,3,4],[2,4]) and subsequence([1,2,3],) but not subsequence([1,2,3],[3,1]) . http://www.cs.ucsd.edu/classes/fa06/cse130/shw/shw9.html (2 of 2) [2/13/2008 5:27:40 PM]...
View Full Document

This homework help was uploaded on 02/14/2008 for the course CSE 130 taught by Professor Jhala during the Fall '06 term at UCSD.

Page1 / 2

hw9 - (a) Write a predicate reverse(X,Y) that is true if...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online