sorting one group of numbers to match another one

Jun 22, 2007 at 12:52am

sorting one group of numbers to match another one

I have two groups of numbers, each one in a coll, with one number per “row”.

One group is a subset of the other – for example:

group A = 1 3 2 5 4
group B = 1 4 5

I want the ordering of the numbers in group B to follow the pattern set in group A; in the example above, I would like group B to be reordered like so:

1 5 4

I can think of brute force ways to do this, but I was looking for something “elegant” – any takers? I can also use lists rather than colls if that helps…

Thanks,
Dan

#32573
Jun 22, 2007 at 1:21am

Not sure if theres an ‘out of the box’ solution I can think of – but if an easier than brute force method exists, I bet you’d find it in L-objects.

Hope this helps

T

#107485
Jun 22, 2007 at 2:11am

It does help Tristram – Lswap is exactly what I need. Thanks!

And thanks Peter Elsea!!!

Dan

At 7:21 PM -0600 6/21/07, Tristram Cox wrote:
>Not sure if theres an ‘out of the box’ solution I can think of – but
>if an easier than brute force method exists, I bet you’d find it in
>L-objects.
>
>Hope this helps

Dan Nigrin
Defective Records
202 Hack / PC-1600 User / VSTi Host / OMS Convert / Jack OS X / Major
Malfunction
http://www.defectiverecords.com

http://www.jackosx.com

#107486
Jun 22, 2007 at 2:30am

Post your solution.

On 6/21/07 10:11 PM, “Dan Nigrin” wrote:

> It does help Tristram – Lswap is exactly what I need. Thanks!
>
> And thanks Peter Elsea!!!
>
> Dan

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson

#107487
Jun 22, 2007 at 9:56am

What about zl sect ?

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 112 184 48 9109513;
#P newex 112 158 57 9109513 prepend set;
#P newex 112 131 57 9109513 zl sect;
#P message 159 67 29 9109513 1 4 5;
#P message 112 104 45 9109513 1 3 2 5 4;
#P connect 1 0 0 0;
#P connect 1 0 2 1;
#P connect 3 0 4 0;
#P connect 2 0 3 0;
#P connect 0 0 2 0;
#P window clipboard copycount 5;

#107488
Jun 22, 2007 at 11:34am

Thanks for forcing the issue Gary – in building the example I realize
now that it will not work, at least without a bit more work. I just
tried playing around with the Lswap help file, and it all seemed to
work fine there — but that’s because the examples I tried it with
there all included “0″ in the list; in my example, in which there’s
no 0 element in the list, it will not work:

#P window setfont “Sans Serif” 9.;
#P message 139 236 75 196617;
#P window linecount 1;
#P newex 139 211 62 196617 prepend set;
#P button 130 133 15 0;
#P newex 170 133 48 196617 loadbang;
#P newex 139 190 36 196617 lswap;
#P message 130 163 34 196617 1 4 5;
#P message 170 162 52 196617 1 3 2 5 4;
#P connect 4 0 1 0;
#P connect 1 0 2 0;
#P connect 2 0 5 0;
#P connect 5 0 6 0;
#P connect 0 0 2 1;
#P connect 3 0 0 0;
#P window clipboard copycount 7;

I’m sure I can find a way around this though…

Dan

At 10:30 PM -0400 6/21/07, Gary Lee Nelson wrote:
>Post your solution.

Dan Nigrin
Defective Records
202 Hack / PC-1600 User / VSTi Host / OMS Convert / Jack OS X / Major
Malfunction
http://www.defectiverecords.com

http://www.jackosx.com

#107489
Jun 22, 2007 at 11:36am

Interesting, thanks! It seems as though zl sect preserves the order
of the list that is given to it in its left inlet, which does seem
like it will work for my purposes. Plus using native objects!

Thanks again,
Dan

At 2:56 AM -0700 6/22/07, e.g.r. wrote:
>What about zl sect ?
>
>#P window setfont “Sans Serif” 9.;
>#P window linecount 1;
>#P message 112 184 48 9109513;
>#P newex 112 158 57 9109513 prepend set;
>#P newex 112 131 57 9109513 zl sect;
>#P message 159 67 29 9109513 1 4 5;
>#P message 112 104 45 9109513 1 3 2 5 4;
>#P connect 1 0 0 0;
>#P connect 1 0 2 1;
>#P connect 3 0 4 0;
>#P connect 2 0 3 0;
>#P connect 0 0 2 0;
>#P window clipboard copycount 5;
>
>

Dan Nigrin
Defective Records
202 Hack / PC-1600 User / VSTi Host / OMS Convert / Jack OS X / Major
Malfunction
http://www.defectiverecords.com

http://www.jackosx.com

#107490
Jun 22, 2007 at 1:40pm

Strings of max objects are clumsy for this sort of thing. Perhaps java,
lisp, or my personal favorite, APL (A Programming Language). In APL this is
one line of code. Java and maxlisp (is it UB yet) are already available in
max. APL is a fantasy of mine. What ever happened to pyrite?

On 6/22/07 7:34 AM, “Dan Nigrin” wrote:

> Thanks for forcing the issue Gary – in building the example I realize
> now that it will not work, at least without a bit more work. I just
> tried playing around with the Lswap help file, and it all seemed to
> work fine there — but that’s because the examples I tried it with
> there all included “0″ in the list; in my example, in which there’s
> no 0 element in the list, it will not work:

Cheers
Gary Lee Nelson
Oberlin College
http://www.timara.oberlin.edu/GaryLeeNelson

#107491
Jun 26, 2007 at 1:07pm

Gary Lee Nelson schrieb:
> What ever happened to pyrite?

Turned into Supercollider long ago….

Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com

#107492

You must be logged in to reply to this topic.