Re: i am a prolog beginner pls help me in getting this



jaya chandra wrote:
On Apr 18, 11:22 pm, jaya chandra <rams.13...@xxxxxxxxx> wrote:
On Apr 18, 1:26 pm, Jussi Piitulainen <jpiit...@xxxxxxxxxxxxxxxx>
wrote:



jaya chandra writes:
Joachim Schimpf wrote:
rams.13...@xxxxxxxxx wrote:
?- everyother([3,4,11,0,9,19],X).
X = [3, 11, 9] ;
No
[snip]
This code gives the answers you want:
everyother([3,4,11,0,9,19],[3, 11, 9]).
...
hey thanku for the help.but it should be written generally means not
only for that numbers but for all the input please help me in the
code pls help
Can you write a solution for lists of length one? Lists of length two?
Lists of length at most two? List of length at most three?
we have to write a program which gives output for the following
examples


I am asking [for a definition of the] 'everyother' function, man.


Has it occurred to you that you might be able to derive the
sought-after general definition on your own?

You should always begin by writing down an ordinary definition of the
Prolog predicate you want.

E,g,

eo(L1,L2) is true if and only if list L2 consists of
the odd-numbered members of list L1 in the order they occur.

Examples:

eo([a],[a]).

eo([a,b],[a]).

eo([a,b,c],[a,c]).

The examples generalize easily:

eo([X1],[X1]).
eo([X1,X2],[X1]).
eo([X1,X2,X3],[X1,X3]).

This leaves the case of lists with or more members.

eo([X1,X2,X3,X4|L1],[X1,X3|L2]) if something...

Furthermore, the empty list contains no members, hence no odd-numbered
members, so we /must/ admit

eo([],[]).

Collecting the bits and piece of our fragmentary provisional
definition, and some tidying up, we get

eo([],[]).
eo([X1],[X1]).
eo([X1,_],[X1]).
eo([X1,_,X3],[X1,X3]).
eo([X1,_,X3,_|L1],[X1,X3|L2]) :- something... .

which, after you supply the missing "something", can be tested in
the Prolog Inference Engine and further simplified.

Prolog resembles a piano more that it resembles a hammer: any moron
can hit himself on the head with a hammer the first the he sees one, but
no-one can sit down and start playing Rachmaninov the first time he
sees a piano.

Practice, man, practice! :)

billh

.



Relevant Pages

  • Re: Membership database updates
    ... The main database is in HQ and they send me a list ... of members in my branch. ... If you can help me write a query to do this in less steps it would be ... how do I import the updated lists for Feb and Mar as there is no ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Guild privacy policy
    ... Last year a local quilt shop owner sent us all emails about the sales ... Several other members spoke up and said, "Yeah, she would, and did." ... info, and she did, after explaining that she couldn't afford mailing lists ...
    (rec.crafts.textiles.quilting)
  • RE: SharePoint Services V3, permissions for People and Group lists
    ... I tried the group security and it worked really well when you click on a ... members but still see everyone by just clicking "all people". ... works with multiple clients, and they need a way to share files with clients ... so calendars / events lists. ...
    (microsoft.public.sharepoint.portalserver)
  • Re: terminological obscurity
    ... > with members of the same type. ... > I don't understand what Guido meant, ... > lists were designed to be used " with homogenous members, ... > terminology was part of what was creating some misunderstanding of the ...
    (comp.lang.python)
  • RE: Mailing List from Frontpage
    ... association officers and key members can download an Excel file, ... uncovered with Verio and some other ISPs, only let's you forward to one ... "Mailing Lists" but I suspect it is not for the simple, ...
    (microsoft.public.frontpage.client)