Adding spaces to the middle of a 3digit number (131 turning into 1 3 1)

Rodrigo's icon

I'm trying to implement a streamlined way of sending a matrixctrl (8x8) amount of data, by only sending the messages that have changed.

I'm using sprintf to strip spaces (so 1 3 1 becomes 131) then using zl group and zl unique to spit out the unique changes, and this is all working well (did a workaround to avoid stripping leading zeros).

The problem I'm having now is turning the 3digit numbers I have on my output back into 3 digit lists (131 to 1 3 1).

I did some searching on the forum but I couldn't find out how to keep a number intact, but with spaces in it, using sprintf.

The intended usage for this is to send LED data to a monome but efficiently (so I only send what needs to be changed, and not a a ton of data).

Here's the patch:

Max Patch
Copy patch and select New From Clipboard in Max.

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

hi Rodrigo,
does this help? although it avoids sprintf

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

Hi rodrigo, here is a possible solution

there must be a cleaner solution but I could not think of it right now

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

ok, this is cleaner

Timo Rozendal's icon

kthozoid, your thresh will be tricky with fast messages

kthozoid's icon

Timo, agreed, the time based nature of it poses a risk. your 2nd solution seems the most elegant.

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

how about this as a solution

just using regex

Rodrigo's icon

Interesting math solution Timo, though it's hard to beat the regex example.

Timo Rozendal's icon

yeah regexp ftw :-)
though I am always confused, need to read more tutorials... but that's low priority

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

I usually use something that is kind of a mix between the patches of kthozoid and timo :

the advantage of that kind of solution is that you can have any numbers of digits.
Is there any way to have a regexp solution that would work with any 'length'?
would be great

Wetterberg's icon

ha, yeah timo's last idea was the one I was going with, too.

Wetterberg's icon

@ch you can do a loop and iterate through the list with the regexp patch and then zl group at the end.

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

@ch @wetterberg you mean like this?

big_pause's icon

took me a while to figure that one out, seems that @substitute has the perl /g equiv in there ...

ch's icon

@ch @wetterberg you mean like this?

yes exactly!