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

    Feb 29 2012 | 9:22 am
    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:

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