Forums > Jitter

Need help with list processing!!!

May 31, 2009 | 2:11 pm

Dear Jitterlist!!
At first lines sorry again for bad english Wink

Can anybody help with list processing?
I’ve list with some repeating numbers, and I need to find it and change to unique numbers, for example [max number + 1]…
Repeatings can be came one time, or can be some more, or can have not…
For another one example this is list that I’ve:
1 2 2 3 4 5 6 6
And this is needeed result:
1 2 7 3 4 5 6 8

Hope anybody can advice me, may be through some [zl] sequense, may be through some js or java…

Many thanks for any tip!


May 31, 2009 | 7:19 pm

if i understand correctly, javascript seems like the easiest way to handle this.

just some pseudocode:

var count = 0;
var preval = 0;

for (i in list to process){
  var curval = list[i];
  if(curval = preval) list[i] = ++count;
  preval = curval;
}
outlet(list);

is that helpful?



MIB
May 31, 2009 | 7:20 pm

something like this should do the trick…
right now it is for ints only. for floats you have to make some changes.

– Pasted Max Patch, click to expand. –

May 31, 2009 | 8:15 pm

looks like yep, but I’m not some js advanced (
I’m can’t finished it to working code …


May 31, 2009 | 8:23 pm

It’s amazin god damned great patching ! Thanks
But it have some error – after processing of list that need changes, when I’ve process normal numbered list – it came with error. Look at please!



MIB
May 31, 2009 | 8:41 pm

so you expect me to do all your work for you??
here goes nothing. This might do the trick.

– Pasted Max Patch, click to expand. –

May 31, 2009 | 9:30 pm

Smile
thanks for your interest!
with your patch not all clean again, but it’s beautirful construction !!!
can you say me what are doing subpatcher [p through] ??
I am absolutely confused!!
Cheers!



MIB
May 31, 2009 | 9:36 pm

the [+] object doesn’t let you connect its output to any of its own inputs. by going through a subpatch I trick Max and I can now connect to anything I want to. it’s easy to get stack overflows that way – Max is trying to prevent you from making such a mistake by not allowing the connection in the first place – so you need to be very careful when using that trick…

could you give me a specific example about what isn’t working for you?


May 31, 2009 | 10:26 pm

nice tip!
I’ve attach patch, if you copy compressed, then patch need to restart…

– Pasted Max Patch, click to expand. –


MIB
June 1, 2009 | 5:50 pm

didn’t have much time, but I made a few minor changes (mainly clearing things properly after each run).
I hope this does what you want it to. It’s also a bit messy right now, you might want to go through and put in some triggers…

– Pasted Max Patch, click to expand. –


MIB
June 1, 2009 | 9:09 pm

there still seems to be some funkyness going on. Since I really can’t spend any more time on this (if you figure it out, please let me know) I thought I would instead try a javascript. I have never done javascripting before and figured this would be a good start.
The couple of tests I did seemed more reliable than the previous patch. Save the Javascript code as listTEST.js

inlets = 1;
outlets = 1;

var count = 0;
var maxCount = 0;
var preVal = 0;
var curVal = 0;

function list() {

var i;

len = arguments.length;

for (i = 0; i < len; i++) {
count = arguments[i];
if (count > maxCount) maxCount = count; //get highest number in list
}
// post(maxCount);

for ( i = 0; i < len; i++) { //substitute
curVal = arguments[i];

if (curVal == preVal) {
arguments[i] = ++maxCount;
}

preVal = curVal;

// post(arguments[i]);

}

maxCount = 0;
preVal = 0;

var a = arrayfromargs(arguments);

outlet(0, a);
}

– Pasted Max Patch, click to expand. –

June 2, 2009 | 9:09 am

Hiya, MIB!
Once again thanks for time which you spend for my problems.
Both decisions again have errors, but both variants is good training for me. Having looked your examples I hope a little to learn using JS in Max and to raise my level of patching…
I’ll let you know if there will be any success in it!
Cheers!


June 8, 2009 | 11:35 am

Hiya MIB & list, I ask for solution Jasch, and this is his js
Works!

Many thaaaanks Jasch !

/*
duplicate replace
jasch 20090608

*/

function list()
{
var maximum = -1234567890;
var inlist = arrayfromargs(arguments);

// find highest value in list
for(var i = 0; i < inlist.length; i++){
if(inlist[i] > maximum){
maximum = inlist[i];
}
}

// iterate through list and replace duplicates by maximum+1
for(var i = 0; i < inlist.length; i++){
for(var j = 0; j < inlist.length; j++ ){
if(inlist[i] === inlist[j] && i != j){
inlist[j] = ++maximum;
}
}
}

outlet(0, inlist);
}

/*
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 249 118 97 196617 44 45 46 37 21 44;
#P message 112 232 238 196617 44 45 46 37 21 47;
#P newex 112 211 62 196617 prepend set;
#P message 112 115 97 196617 1 2 3 4 5 5 6 7 8 9;
#P newex 112 167 88 196617 js dup_replace.js;
#P hidden connect 2 0 3 0;
#P connect 0 0 2 0;
#P connect 1 0 0 0;
#P connect 4 0 0 0;
#P window clipboard copycount 5;
*/


Viewing 13 posts - 1 through 13 (of 13 total)