Re: i am a prolog beginner pls help me in getting this
- From: student <nospam@xxxxxxxxxxx>
- Date: Fri, 20 Apr 2007 00:22:16 GMT
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:we have to write a program which gives output for the followingJoachim Schimpf wrote:Can you write a solution for lists of length one? Lists of length two?rams.13...@xxxxxxxxx wrote:hey thanku for the help.but it should be written generally means not?- everyother([3,4,11,0,9,19],X).This code gives the answers you want:
X = [3, 11, 9] ;
No
[snip]
everyother([3,4,11,0,9,19],[3, 11, 9]).
...
only for that numbers but for all the input please help me in the
code pls help
Lists of length at most two? List of length at most three?
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
.
- Follow-Ups:
- Re: i am a prolog beginner pls help me in getting this
- From: student
- Re: i am a prolog beginner pls help me in getting this
- References:
- i am a prolog beginner pls help me in getting this
- From: rams . 13785
- Re: i am a prolog beginner pls help me in getting this
- From: Joachim Schimpf
- Re: i am a prolog beginner pls help me in getting this
- From: jaya chandra
- Re: i am a prolog beginner pls help me in getting this
- From: Jussi Piitulainen
- Re: i am a prolog beginner pls help me in getting this
- From: jaya chandra
- Re: i am a prolog beginner pls help me in getting this
- From: jaya chandra
- i am a prolog beginner pls help me in getting this
- Prev by Date: Re: i am a prolog beginner pls help me in getting this
- Next by Date: Last call for papers: Workshop on Termination (WST 2007) - Paris
- Previous by thread: Re: i am a prolog beginner pls help me in getting this
- Next by thread: Re: i am a prolog beginner pls help me in getting this
- Index(es):
Relevant Pages
|
|