Help with lists.
- From: "joonix" <jooonix@xxxxxxxxx>
- Date: 16 Aug 2005 21:35:36 -0700
Greetings,
I have just started learning prolog. I come from a C/C++/Java
background and I am having a very hard time getting my head around this
style of programming.
Can some one please offer me some assistance in creating the following
relationships:
1) A relation flatten( X, Y ) that holds when Y is a list structure
that contains the same elements as X, in the same order, but with no
nested lists beyond the first level. In other words, Y may contain
either atomic elements or other lists, but these may not contain any
nested lists.
Eg:
|?- flatten1( [a, b, [c,d], [[e]]], Y).
Y = [ a, b, [c, d], [e]].
no
|?- flatten1( [a,[b],[[[c]], [d,e]]], X).
X = [a,[b],[c,d,e]].
no
2) A predicate no-triplicates(List1, List2) that replaces all
occurrences of any element that appears three or more times in List1
(i.e., triplicate members) with a single occurrence of that element to
generate List2. This single occurrence must occupy the position in the
list held by the first occurrence of the triplicate member in List1.
Duplicate occurrences are left unchanged. For instance, if the input
list List1 is [1, 2, 3, 2, 3, 3, 4], then the output list List2 must be
[1, 2, 3, 2, 4].
Thanks in advance,
joo.
.
- Follow-Ups:
- Re: Help with lists.
- From: student
- Re: Help with lists.
- From: Torkel Franzen
- Re: Help with lists.
- Prev by Date: comp.lang.prolog Frequently Asked Questions
- Next by Date: Re: Help with lists.
- Previous by thread: completeness and forall
- Next by thread: Re: Help with lists.
- Index(es):
Relevant Pages
|