Re: Need help with lists !



On Nov 13, 4:33 am, mari...@xxxxxxxxx wrote:
I have 3 tasks, but I'm a beginner at Prolog:( Does anyone have any
ideas or examples? Thanks. (sorry for my english).

1. equal(List, Delta):
In the List two adjacent elements doesn't differ more than Delta.

For example: goal: equal ([1,3,5,4,3,2,4,2], 2).
true.

2. insert(S,K,R):
Insert K into the list S. List element before K should be smaller than
K and element after K - bigger than K.

For example: goal: insert([10,2,14,8,1], 13, R).
R = [10,2,13,14,8,1].

3. common (S, E):
Element E is the most common in the list S.
For example: goal: common([a,a,c,a,b,b,a,g],E).
E=a.

Defining recursive predicates in Prolog is similar to
proofs by induction. There are one or more "basis"
cases that are simplest/final case to resolve, and
there are one or more rules which reduce the more
complicated/lengthier cases to simpler/shorter ones.

So it may help to "think backwards" and settle the
simplest cases first. In the exercise where a list
should not have adjacent elements that differ by
more than parameter Delta, you might start by
writing the clauses/facts that express success for
the very shortest lists. Then work out a rule
which reduces the solution of a longer list to a
goals involving a shorter list (preferably the tail
of the original input list).

regards, chip

.



Relevant Pages

  • delta JT360 assembly problem - web site useless
    ... Recently purchased a Delta JT360 jointer. ... I suspect they ... link for getting an online copy of the manuals, parts lists, etc., ... obvious links for manuals anyway. ...
    (rec.woodworking)
  • Re: delta JT360 assembly problem - web site useless
    ... Recently purchased a Delta JT360 jointer. ... link for getting an online copy of the manuals, parts lists, etc., ... obvious links for manuals anyway. ... When I had a problem assembling my Jet contractor's saw (cracked ...
    (rec.woodworking)
  • Re: Delta site
    ... parts lists, you now get sent directly to the servicenet site? ... I noticed that they no longer have the literature online for one of my ... even though they had it a week before the ServiceNet site ... The Black & Deckerization of Delta is not looking good to me at this ...
    (rec.woodworking)
  • Smth unnatural
    ... I have 2 lists ... ... And third list @Delta has elements like = ... And the graf will be like this: ... print "\nDati functia de tranzitie (function Delta) dupa model\n ...
    (perl.beginners)
  • Create logical custom drop down list
    ... I am working on building a spreadsheet which populates values in cells based ... All of this is in drop down lists (data ... if I enter Automobile in A2, I want B2 to be restricted to Ford, GM, BMW, ... if I enter Airline in A2, I want B2 to only show Delta, Northwest, etc. ...
    (microsoft.public.excel.programming)