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

Feb 29, 2012 at 9:22am

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 (8×8) 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:

– Pasted Max Patch, click to expand. –
#62043
Feb 29, 2012 at 9:48am

hi Rodrigo,
does this help? although it avoids sprintf

– Pasted Max Patch, click to expand. –
#224112
Feb 29, 2012 at 9:53am

Hi rodrigo, here is a possible solution

– Pasted Max Patch, click to expand. –

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

#224113
Feb 29, 2012 at 9:56am

ok, this is cleaner

– Pasted Max Patch, click to expand. –
#224114
Feb 29, 2012 at 9:56am

kthozoid, your thresh will be tricky with fast messages

#224115
Feb 29, 2012 at 9:59am

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

#224116
Feb 29, 2012 at 11:48am

how about this as a solution

– Pasted Max Patch, click to expand. –

just using regex

#224117
Feb 29, 2012 at 3:03pm

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

#224118
Feb 29, 2012 at 3:24pm

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

#224119
Feb 29, 2012 at 11:44pm

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

– Pasted Max Patch, click to expand. –

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

#224120
Mar 1, 2012 at 5:51am

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

#224121
Mar 1, 2012 at 5:52am

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

#224122
Mar 1, 2012 at 9:03am

@ch @wetterberg you mean like this?

– Pasted Max Patch, click to expand. –
#224123
Mar 1, 2012 at 9:11am

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

#224124
Mar 1, 2012 at 11:40am

@ch @wetterberg you mean like this?

yes exactly!

#224125

You must be logged in to reply to this topic.