Question: Replacing defined elements in a list

Hello

I'd like to perform following operation as gracefully and computationally inexpensive as possible:

b := [[2, 3], 1, 2, 3, 4, 5]
c := b[2 .. nops(b)]
c[b[1, 1]] := c[b[1, 2]]
c := ListTools:-MakeUnique(c)
c[b[1, 1]] := max(c) + 1;

b[1] always contains a list of two consecutive indices which should be combined into one element of the list and having assigned the largest integer in the list. In the about example:

> reset;
> b := [[2, 3], 1, 2, 3, 4, 5];
                           [[2, 3], 1, 2, 3, 4, 5]
> c := b[2 .. nops(b)];
                               [1, 2, 3, 4, 5]
> c[b[1, 1]] := c[b[1, 2]];
                                      3
> c;
                               [1, 3, 3, 4, 5]
> c := ListTools:-MakeUnique(c);
                                [1, 3, 4, 5]
> c[b[1, 1]] := max(c)+1;
                                      6
> c;
                                [1, 6, 4, 5]

Thanks for any input regarding this.

Best Regards

Roberto

Please Wait...