Author Message

I am trying to do the following:

1) Find the 3rd element of a list
2) whether a list is a concatenation of three copies of the same sublist.

don't know where to start. I've thought about and tried to write some code
but I'm at a very confused stage! please if you can give me a start I would
be eternally grateful.

Fri, 30 May 2003 15:01:59 GMT

Quote:
>I am trying to do the following:

>1) Find the 3rd element of a list
>2) whether a list is a concatenation of three copies of the same sublist.

>don't know where to start. I've thought about and tried to write some code
>but I'm at a very confused stage! please if you can give me a start I would
>be eternally grateful.

For 1 you don't even need to use 'append'.  X is the third element of a
list if the first element is something, and the second element is
something, and the third element is X.

A list is a concatenation of three copies of the same sublist if you can
append something to itself and then append that same thing to the
concatenation, and get the given list.

Nick
--

Sun, 01 Jun 2003 03:41:50 GMT
Start from chapter 1

if you don't have a book, there's plenty of tutorials available on the web

1) find the 3rd element of a list?
find_third([_, _, THIRD | _ ], THIRD).

test with
find_third([h, e, l, l, o], THIRD).

2) concatenation of three copies
- only one level deep
triple([A, A, A | _ ]) :- !.
triple([A, B, C | TAIL]) :-
triple([B, C | TAIL]).

test
triple([h, e, l, l, l]).

good luck
if you haven't figured out the code above, tough shit

Kee

Quote:
> I am trying to do the following:

> 1) Find the 3rd element of a list
> 2) whether a list is a concatenation of three copies of the same sublist.

> don't know where to start. I've thought about and tried to write some code
> but I'm at a very confused stage! please if you can give me a start I
would
> be eternally grateful.

Sun, 01 Jun 2003 21:55:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages