listoperations 
Author Message
 listoperations

Hallo,

I'm new to prolog and want to do the following listoperation:

Replace two element of a list (in a row) at a specific position.
Example:
[a,s,l,a,b,c]
replace s,l -> x,y  (replace elements at position 2 and 3)
[a,x,y,a,b,c]

Could anybody help me? A list of common listopration woulb be nice too...

Thanks.
Frank



Tue, 28 Jun 2005 05:01:56 GMT  
 listoperations

Quote:

> Hallo,

> I'm new to prolog and want to do the following listoperation:

> Replace two element of a list (in a row) at a specific position.
> Example:
> [a,s,l,a,b,c]
> replace s,l -> x,y  (replace elements at position 2 and 3)
> [a,x,y,a,b,c]

> Could anybody help me? A list of common list operations woulb be nice too...

> Thanks.
> Frank

   Try

        :- [a,s,l,a,b,c] = [a,X,Y,a,b,c].



Tue, 28 Jun 2005 07:04:04 GMT  
 listoperations



Quote:

> > Hallo,

> > I'm new to prolog and want to do the following listoperation:

> > Replace two element of a list (in a row) at a specific position.
> > Example:
> > [a,s,l,a,b,c]
> > replace s,l -> x,y  (replace elements at position 2 and 3)
> > [a,x,y,a,b,c]

> > Could anybody help me? A list of common list operations woulb be nice
too...

> > Thanks.
> > Frank

>    Try

>         :- [a,s,l,a,b,c] = [a,X,Y,a,b,c].

Thanx , but thats not what I want to do. I try to explain it a better:
I want to solve a riddle, that deals with 10 glasses in a row (mixture of
empty and full glasses).
At the beginning the glasses look like that :  [f,f,f,f,e,e,e,e]     f= full
e=empty
the rule is: take two glasses from anywhere (but in a row) and append them
to the nose or tale or move them to the empty space (more than one empty
place x,x is not allowed)
example:  [f,f,x,x,e,e,e,e,f,f]    x = place holder
then you do it again and again:
[f,f,e,e,e,e,x,x,f,f]
[f,x,x,e,e,e,f,e,f,f]
[f,f,f,e,e,e,f,e]
...
aim is:  [f,e,f,e,f,e,f,e] or  [e,f,e,f,e,f,e,f]

I have to solve this for next week, hopefully anybody can help me.
I'm more into C, C++,... but  prolog is a big ? for me :-)



Tue, 28 Jun 2005 09:29:27 GMT  
 listoperations


Quote:




> > > Hallo,

> > > I'm new to prolog and want to do the following listoperation:

> > > Replace two element of a list (in a row) at a specific position.
> > > Example:
> > > [a,s,l,a,b,c]
> > > replace s,l -> x,y  (replace elements at position 2 and 3)
> > > [a,x,y,a,b,c]

> > > Could anybody help me? A list of common list operations woulb be
nice
> too...

> > > Thanks.
> > > Frank

> >    Try

> >         :- [a,s,l,a,b,c] = [a,X,Y,a,b,c].

> Thanx , but thats not what I want to do. I try to explain it a
better:
> I want to solve a riddle, that deals with 10 glasses in a row
(mixture of
> empty and full glasses).
> At the beginning the glasses look like that :  [f,f,f,f,e,e,e,e]
f= full
> e=empty
> the rule is: take two glasses from anywhere (but in a row) and
append them
> to the nose or tale or move them to the empty space (more than one
empty
> place x,x is not allowed)
> example:  [f,f,x,x,e,e,e,e,f,f]    x = place holder
> then you do it again and again:
> [f,f,e,e,e,e,x,x,f,f]
> [f,x,x,e,e,e,f,e,f,f]
> [f,f,f,e,e,e,f,e]
> ...
> aim is:  [f,e,f,e,f,e,f,e] or  [e,f,e,f,e,f,e,f]

Try reversing the list.

Quote:
> I have to solve this for next week, hopefully anybody can help me.
> I'm more into C, C++,... but  prolog is a big ? for me :-)

You had better get on with then. Good luck!

Daniel



Tue, 28 Jun 2005 10:43:51 GMT  
 listoperations
"Daniel Dudley" skrev i melding

[snipped]

Quote:
> Try reversing the list.

No, that won't work -- I misread the problem.
The rest of the message stands though. :-)

Daniel



Tue, 28 Jun 2005 10:47:37 GMT  
 
 [ 5 post ] 

 Relevant Pages 
 

 
Powered by phpBB® Forum Software