get the range from a number in a list

saturnin79's icon

maybe a dummy question, sorry for the hassle. So I have a list of, say 4 numbers : 2 4 9 11 and when I get the number - say 4 - from another part of the patch, I'm looking for a way to test this number in the list below and output it's range, in fact here 2.

I can't figure it out with zl, as zl nth gives me the value of the nth element of the list, and I need its range.

Thanks for your help.

laonikoss's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I am not sure if I understand what you mean by "range" - do you mean the position of the item on the list? An easy solution is this:

However, this only works if you DON'T have repeating numbers in your initial list of numbers. Can't think of anything else (i don't really work with lists much), so maybe someone more knowledgeable on [zl] or other list-manipulation objects can help you out more (I'm curious as to the answer too)

saturnin79's icon

thanks - a more dummy one : how to save your text as a maxpatch (on a mac) ? thanks.

ShelLuser's icon

Copy the whole kaboodle in your clipboard (so from ---begin to ---end, including those lines.

Then in the Max window choose either File -> New from clipboard or press its key function (on Windows control-alt-N, dunno on Mac).

saturnin79's icon

Thanks, the patch works for me