Adding spaces to the middle of a 3digit number (131 turning into 1 3 1)
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:
hi Rodrigo,
does this help? although it avoids sprintf
Hi rodrigo, here is a possible solution
there must be a cleaner solution but I could not think of it right now
ok, this is cleaner
kthozoid, your thresh will be tricky with fast messages
Timo, agreed, the time based nature of it poses a risk. your 2nd solution seems the most elegant.
how about this as a solution
just using regex
Interesting math solution Timo, though it's hard to beat the regex example.
yeah regexp ftw :-)
though I am always confused, need to read more tutorials... but that's low priority
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
ha, yeah timo's last idea was the one I was going with, too.
@ch you can do a loop and iterate through the list with the regexp patch and then zl group at the end.
@ch @wetterberg you mean like this?
took me a while to figure that one out, seems that @substitute has the perl /g equiv in there ...
@ch @wetterberg you mean like this?
yes exactly!