Question: Append number to a list

Experts,

This may sound like a dumb question, but i'm seeking a procedure to do it better.
 

``

 

with(combinat, setpartition) :
P := [$2..5] :

Tours := setpartition(P);M:=nops(Tours)

[[[5], [2, 3, 4]], [[2], [5], [3, 4]], [[3], [5], [2, 4]], [[4], [5], [2, 3]], [[2], [3], [4], [5]], [[2, 3, 4, 5]], [[2, 5], [3, 4]], [[2], [3, 4, 5]], [[2, 4], [3, 5]], [[3], [2, 4, 5]], [[2, 3], [4, 5]], [[4], [2, 3, 5]], [[3], [4], [2, 5]], [[2], [4], [3, 5]], [[2], [3], [4, 5]]]

 

15

(1)

 

number of elements in each 'group'

seq(nops(Tours[i]),i=1..nops(Tours))

2, 3, 3, 3, 4, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3

(2)

 

i need to add 1 to each 'subgroup' : These are the first two:

[[[1,op(Tours[1,1])],[1,op(Tours[1,2])]],[[1,op(Tours[2,1])],[1,op(Tours[2,2])],[1,op(Tours[2,3])]]]

[[[1, 5], [1, 2, 3, 4]], [[1, 2], [1, 5], [1, 3, 4]]]

(3)

 

I need to add 1 to each 'subgroup' in a more automatic way.

``


 

Download add_1.mw

 

Please Wait...