< Back to IRCAM Forum

Grouping a list into sublists in wich the sum of its elements is a given nu

Hy everyone,

I’m trying to built this patch for a while now and I think it’s time to give up and ask for help. I think this is a quite simple thing to do but I got stuck in a last procedure.

I want to segment a list into sublists with a special charcteristic: the sum of its elements must be equal to a value that I choose from the beggining.
I built a patch that can do exactly that but only one time. The pacth gives me two outputs: the first sublist result that I want to use (with the right sum of its elemments) and the rest of the main list (that is supposedly to pass trough the function again). That’s where I got stuck! I can’t send this new list again to the beggining of the patch. I gues the answer will be some recursive proccedure but I wasn’t able to do that. I tried but it didn’t work. I went over the tutorials and documentations but the examples weren’t enough for me to understand the concept.

Can someone help me?

Thank you very much!

Hi,

If i correctly understood your quest, you will be needing the group-list method it will do exactly what you are looking for.

Best
K

Recursion is well documented in the OM-Tutorials, Tutorials 36 to 39.
There is another way of programing recursion see the patches below.

fonction-recursive.omp (4.88 KB)

Hy Karim,

Actually the group-list method doesn’t work for me in this situation because, if I’m not doing anything wrong, this method groups items accordinly to a list of quantity of elements and not accordinly to the sum of its elements.

Let me give you an example of what I’m trying to do. Imagine I have this list:

(3 3 4 7 4 3 3 3 4 4 7 7 7 4 7 3 4 4 3 3 7 7)

I want to segment it when the sum of its elements get 50, so I would have:

(3 3 4 7 4 3 3 3 4 4 7 5) (2 7 4 7 3 4 4 3 3 7 7)

Observe that the element in “posn-match” 11 had to be divided in a 5 (at the end of the first sublist) and a 2 (at the beggining of the second one) so the proportions of the main list could be maintained.

The thing is, the way I built this patch, I can do that procedure once. Since I’m working with big lists I need a patch that can work trough the main list multiple times.

Do you have any suggestion?

Thank you very much!

Alex

Hy Jean Michel,

Thank you for your patches, I’ll study them!
And I just found your blog. Lots of interresting articles, locking foward to read them.

All the best to you to

Alex

Ok
Got you

here is a lisp code . Put it in the patches folder of OM and THEN launch om

Just call group-max function (option+click in a ptch)
it will do the trick.

I guess it is possible to do it graphically but i believe it will be really hard to.

Best
K

group-max.lisp (589 Bytes)

Mr. Karim,

I don’t know how to thank you. That was exactly wat I wanted and it is working perfectly fine. Thank’s a lot again for your generosity.

All the best,

Alex