Need help with list processing!!!

May 31, 2009 at 2:11pm

Need help with list processing!!!

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!

#44179
May 31, 2009 at 7:19pm

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?

#158770
May 31, 2009 at 7:20pm

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. –
#158771
May 31, 2009 at 8:15pm

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

#158772
May 31, 2009 at 8:23pm

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!

#158773
May 31, 2009 at 8:41pm

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. –
#158774
May 31, 2009 at 9:30pm

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!

#158775
May 31, 2009 at 9:36pm

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?

#158776
May 31, 2009 at 10:26pm

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

– Pasted Max Patch, click to expand. –
#158777
Jun 1, 2009 at 5:50pm

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. –
#158778
Jun 1, 2009 at 9:09pm

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. –
#158779
Jun 2, 2009 at 9:09am

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!

#158780
Jun 8, 2009 at 11:35am

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;
*/

#158781

You must be logged in to reply to this topic.