nested list



Thanks for both your answers!

About the first solution I'm afraid I didn't explain it clearly (sorry for
my bad english :D):
suppose we have to fill an array of fixed length (say 6) with letters from
the alphabet of the first m positive integers (say {1,...8}), I'm trying to
enumerate every possible way of doing it (recording it in a list containig
lists, every list is a way of fill the array). I tried with endcons but it
seems not to do the job (i.e. there is not only a single completion of
[1,2] indeed [1,2,3],[1,2,4],[1,2,5] are possible beginnings of a filling
of such an array).

The second solution does the trick!

Still wondering whether it is possible to achieve this results just map-ing
append-ing and makelist-ing :D

Again, thanks for all your answers and of course for your kind welcomes
Alessandro



On Wed, Mar 20, 2013 at 10:38 AM, Jaime Villate <villate at fe.up.pt> wrote:

> On 03/20/2013 02:24 AM, Alessandro Campagni wrote:
>
>> Hi everybody,
>> this is my first post here, I'm a very beginner so pardon me if my
>> question seems trivial.
>>
> Hello,
> and welcome. Please feel free to ask anything even if it looks trivial.
>
>
>
>> I'm building a list starting from a list of lists, appending to each one
>> every single value taken from another list. Let me get this straight with
>> an example:
>>
>> this is the starting list
>> ts:[[1,2],[1,3],[1,4],[2,3],[**2,4],[3,4]]
>> now for every [x,y] i should concatenate it with every element of the
>> following list [y+1,y+2,...,n] where n is fixed.
>>
>> This is what I tried:
>>
>> map (lambda ([x], append (makelist (append (x, [y]), y, last (x) + 1,
>> 5))), ts);
>>
>> map (lambda ([x], map (lambda ([y], append (x, [y])), makelist (z, z,
>> last (x) + 1, 5))), ts);
>>
>> makelist (makelist (append (x, [y]), y, last (x) + 1, 5), x, ts);
>>
>> I always get:
>> [[[1,2,3],[1,2,4],[1,2,5]],[[**1,3,4],[1,3,5]],[[1,4,5]],[[2,**
>> 3,4],[2,3,5]],[[2,4,5]],[[3,4,**5]]]
>>
>> but what I really need is
>> [[1,2,3],[1,2,4],[1,2,5],[1,3,**4],[1,3,5],[1,4,5],[2,3,4],[2,**3,5],[2,4,5],[3,4,5]]
>> (i.e. just a list of lists).
>>
>> Now, the question: Is it possible without using for's or if's?
>>
>> I played around with flatten but it didn't help me!
>>
>>
> Well, that's definitely not a trivial question :) I don't know how to make
> flatten to flatten just one level of lists, so the only solution I can
> think of is using a for loop:
>
> (%i1) ts: [[1,2],[1,3],[1,4],[2,3],[2,4]**,[3,4]]$
> (%i2) p:[]$
> (%i3) for x in ts do p:append (p, makelist (append (x, [y]), y, last (x) +
> 1, 5))$
> (%i4) p;
> (%o4) [[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3, 5], [1, 4, 5],
> [2, 3, 4], [2, 3, 5], [2, 4, 5], [3, 4, 5]]
>
> Regards,
> Jaime
>
>