0 Replies - 663 Views - Last Post: 15 April 2009 - 07:24 AM Rate Topic: -----

#1 chetah  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 111
  • Joined: 17-November 07


Post icon  Posted 15 April 2009 - 07:24 AM

I am looking a problem here and need some help

recursive definition of append

append([H|T1], A, [H|T2]):-(T1, A, T2)

(a.) ?-append(L,[x,z],[y,x,z]

my answer
L3 = [L]|[Lo]
?- append ([], [x,y], L0.
L0 = []|L1

(b.) write rule for append1(l1, l2, l3,l4) to be true if and only if l4 is the same as l1,l2, and l3 append in that order

my answer
append1([], A, A, A).
append1([H|T1], A, A, [H|T4]):-append1(T1, A, A, T4)

(c.) using append write rule to define shorten(l1, l2) to be true if and only if l2 can be obtained by removing the first and last elements of l1.

shorten(L1, L2) :- shorten([H]|[_N], L2)

(d.) use shorten write rule that defines even(l) to be true if and only if l is a list of even number
shorten(l1,l2):-even(l,X) //where x is 2

(e.) state steps prolog would take to solve shorten([1,2,3],l)

need some guidance struggling here

Is This A Good Question/Topic? 0
  • +

Page 1 of 1