## Choosing highest of 3 numbers…?

Jan 20, 2007 at 3:59pm

# Choosing highest of 3 numbers…?

2 years ago, I was writing a patcher in which I needed to determine which of 3 given numbers was the largest. Eventually the manual reminded me about funbuffs, and I simply filled one with the 3 numbers and sent it the ‘max’ message. But until I came upon that easy solution, I was startled at the headaches this seemingly simple task was giving me, as a pure MAX process. After more than a year of occasional work at it, this is the simplest solution I could find… and it’s still pretty Baroque. Maybe there’s something blindingly obvious I overlooked (aside from the funbuff workaround)… but I thought someone might be intrigued to find a simpler solution. I’m obviously still at a fairly elementary level.
#P window setfont “Sans Serif” 9.;
#P window linecount 2;
#P comment 113 324 57 196617 Which of 3 is highest;
#P comment 172 325 57 196617 Highest of 3 numbers;
#P number 142 311 22 9 1 3 8359 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 178 312 37 9 0 0 8356 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 175 31 46 196617 13 8 21;
#P message 138 31 34 196617 3 8 5;
#P message 101 31 34 196617 0 1 2;
#P newex 179 290 53 196617 switch 3;
#P newex 186 268 49 196617 cycle 3;
#P newex 187 249 61 196617 0 0 0;
#P newex 187 227 24 196617 3;
#P newex 142 270 27 196617 + 1;
#P newex 185 161 23 196617 v g;
#P newex 121 250 21 196617 v g;
#P newex 89 138 46 196617 t clear i;
#P newex 121 228 31 196617 sel;
#P newex 123 208 27 196617 * 2;
#P newex 127 188 22 196617 >;
#P newex 139 161 44 196617 offer;
#P newex 91 118 27 196617 >;
#P newex 90 98 51 196617 route 1 0;
#P newex 96 75 49 196617 funnel 2;
#P newex 100 55 73 196617 cycle 3;
#P message 64 216 29 196617 max;
#N funbuff 0;
#P newobj 63 232 42 196617 funbuff;
#P window linecount 5;
#P comment 7 168 114 196617 This is my 3rd version: if you can come up with a simpler one , please let me know… besides the obvious;
#P fasten 11 1 7 0 130 158 144 158;
#P fasten 11 1 13 0 130 155 190 155;
#P connect 10 1 14 0;
#P fasten 10 1 16 0 149 247 192 247;
#P connect 10 0 12 0;
#P fasten 10 0 15 0 163 226 192 226;
#P connect 7 0 8 1;
#P fasten 7 0 16 2 144 181 242 181;
#P connect 4 0 5 0;
#P fasten 4 0 7 0 98 95 144 95;
#P fasten 3 2 8 0 167 185 132 185;
#P fasten 3 2 16 1 217 158;
#P connect 2 0 1 0;
#P connect 6 0 11 0;
#P connect 5 0 6 0;
#P connect 3 0 4 0;
#P fasten 21 0 3 0 180 51 105 51;
#P fasten 20 0 3 0 143 51 105 51;
#P fasten 19 0 3 0 106 51 105 51;
#P connect 5 1 6 1;
#P connect 9 0 10 0;
#P connect 8 0 9 0;
#P connect 3 1 4 1;
#P fasten 11 0 7 0 94 159 144 159;
#P fasten 12 0 14 0 126 269 147 269;
#P connect 14 0 23 0;
#P connect 18 0 22 0;
#P connect 17 0 18 0;
#P connect 16 0 17 0;
#P connect 15 0 16 0;
#P connect 17 1 18 2;
#P connect 17 2 18 3;
#P window clipboard copycount 26;

#29820
Jan 20, 2007 at 4:30pm

Dear David,

Below is a simpler solution (3 objects) without using funbuff…

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 54 160 39 9109513 trigger l;
#P message 128 110 46 9109513 13 8 21;
#P message 91 110 34 9109513 3 8 5;
#P message 54 110 34 9109513 0 1 2;
#P window linecount 2;
#P comment 25 289 57 9109513 Which of 3 is highest;
#P comment 99 290 57 9109513 Highest of 3 numbers;
#P number 54 276 22 9 1 3 8359 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 105 277 37 9 0 0 8356 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 54 244 38 9109513 zl nth 1;
#P newex 54 217 32 9109513 zl sub;
#P newex 105 189 49 9109513 maximum;
#P window linecount 3;
#P comment 70 63 100 9109513 simpler (but doesn’t use even simpler
funbuff solution);
#P window linecount 2;
#P comment 103 153 100 9109513 this necessary only for testing…;
#P comment 122 224 100 9109513 …so a 3 object solution.;
#P connect 10 0 13 0;
#P connect 11 0 13 0;
#P connect 12 0 13 0;
#P connect 13 0 4 0;
#P connect 4 0 5 0;
#P connect 5 0 7 0;
#P connect 3 0 4 1;
#P connect 13 0 3 0;
#P connect 3 0 6 0;
#P window clipboard copycount 14;

Yours truly,
David

David Wright wrote:
> 2 years ago, I was writing a patcher in which I needed to determine
> which of 3 given numbers was the largest. Eventually the manual
> reminded me about funbuffs, and I simply filled one with the 3
> numbers and sent it the ‘max’ message. But until I came upon that
> easy solution, I was startled at the headaches this seemingly simple
> task was giving me, as a pure MAX process. After more than a year of
> occasional work at it, this is the simplest solution I could find…
> and it’s still pretty Baroque. Maybe there’s something blindingly
> obvious I overlooked (aside from the funbuff workaround)… but I
> thought someone might be intrigued to find a simpler solution. I’m
> obviously still at a fairly elementary level.

#93832
Jan 20, 2007 at 4:33pm

this one is simpler :)
_y.

#P window setfont “Sans Serif” 9.;
#P number 44 132 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 118 62 46 9109513 13 8 21;
#P message 81 62 34 9109513 3 8 5;
#P message 44 62 34 9109513 0 1 2;
#P newex 44 102 73 9109513 maximum;
#P connect 0 0 4 0;
#P connect 3 0 0 0;
#P connect 2 0 0 0;
#P connect 1 0 0 0;
#P window clipboard copycount 5;

#93833
Jan 20, 2007 at 4:34pm

#93834
Jan 20, 2007 at 4:38pm

But it doesn’t output the index of the highest number – which was
David’s request…

Yours truly,
David

e.g.r. wrote:
> this one is simpler :)
> _y.
>
>
> #P window setfont “Sans Serif” 9.;
> #P number 44 132 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P message 118 62 46 9109513 13 8 21;
> #P message 81 62 34 9109513 3 8 5;
> #P message 44 62 34 9109513 0 1 2;
> #P newex 44 102 73 9109513 maximum;
> #P connect 0 0 4 0;
> #P connect 3 0 0 0;
> #P connect 2 0 0 0;
> #P connect 1 0 0 0;
> #P window clipboard copycount 5;
>
>
> ————————————————————————
>

#93835
Jan 20, 2007 at 4:40pm

Ah, yes, the good ol’ Swiss-Army-knife mind-bogglingly multi-function ZL! I have to reread that chapter and bone up on it. Thanks for the tip!

Not to be an ingrate, but you could conceivably call this answer just as much a workaround as relying on funbuff. You’re passing off the routine from MAX to the code that runs ZL behind the scenes, so to speak. Not that there’s anything wrong with that, in practical terms.

Maybe I should clarify my request: using only high-level MAX objects like numbers and binops, create a workflow that shows as clearly and simply as possible this comparison task? I showed the problem to one friend who commented, “Oh, you just enjoy driving yourself nuts!” Point taken. :)

David Wright

#93836
Jan 20, 2007 at 4:44pm

ooops, sorry for that.
_y.

#93837
Jan 20, 2007 at 4:46pm

#93838
Jan 20, 2007 at 4:52pm

Wow, the board’s really hopping on this Saturday morning. 3 more replies came in even while I wrote my “Swiss Army” reply.Thanks for the brainpower, folks…

#93839
Jan 20, 2007 at 8:36pm

#93840
Jan 21, 2007 at 7:12am

If you don’t need to know the position of highest number, this is
pretty simple:

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 24 154 39 196617 int;
#P newex 53 112 25 196617 iter;
#P newex 53 133 39 196617 peak;
#P newex 24 88 69 196617 t b l 0;
#P window linecount 2;
#P comment 18 210 57 196617 Highest of 3 numbers;
#P number 24 197 37 9 0 0 8356 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 98 40 46 196617 13 8 21;
#P message 61 40 34 196617 3 8 5;
#P message 24 40 34 196617 0 1 2;
#P connect 5 0 8 0;
#P connect 8 0 3 0;
#P connect 6 0 8 1;
#P connect 5 2 6 1;
#P connect 5 1 7 0;
#P connect 2 0 5 0;
#P connect 1 0 5 0;
#P connect 0 0 5 0;
#P connect 7 0 6 0;
#P window clipboard copycount 9;

Chris Muir | “There are many futures and only one status quo.
cbm@well.com | This is why conservatives mostly agree,

#93841
Jan 21, 2007 at 11:27pm

JOOST REKVELD WINS THE PRIZE!!!

Well, actually, reading that sentence will be the prize for him. BWAHAHAHAHAA! Of course– Why didn’t I think of *2 and *4! The equivalent of bit-shifting to tag each boolean greater-than test with a different value. I often cram 3 values into a funbuff by multiplying one of them by 100, so 3 12 47 gets stored as 3 1247. Same kinda thinking… sorta.

Profuse thanks to all you contestants. My duplicate posts caused some confusion, as one of them didn’t specifically say “greatest number AND ITS INDEX.” Of course without that, a ‘maximum’ routine is simple. OK, back to the real world, for what it’s worth.

P.S. I will look into the Peter Elsea collection– I’ve read about those before…

#93842
Jan 22, 2007 at 12:47pm

David
I don’t know if this helps or is, in fact, simpler, but I do remember
scratching my head over this problem too and still might be missing
something blindingly obvious.
It finds the ‘index’ of lowest number of 5 and I’m sure you can add to
to pass the actual number.
Best
Gorwel
max v2;
#N vpatcher 10 59 1024 762;
#N comlet Max Grey Zone;
#P outlet 35 467 15 0;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 227 431 14 196617 5;
#P message 179 431 14 196617 4;
#P message 131 431 14 196617 3;
#P message 83 431 14 196617 2;
#P message 35 431 14 196617 1;
#P newex 227 410 45 196617 Togedge;
#P newex 179 410 45 196617 Togedge;
#P newex 131 410 45 196617 Togedge;
#P newex 83 410 45 196617 Togedge;
#P newex 35 410 45 196617 Togedge;
#P toggle 227 376 15 0;
#P toggle 179 376 15 0;
#P toggle 131 376 15 0;
#P toggle 83 376 15 0;
#P toggle 35 376 15 0;
#N comlet Out 5;
#P outlet 227 346 15 0;
#N comlet Out 4;
#P outlet 179 346 15 0;
#N comlet Out 3;
#P outlet 131 346 15 0;
#N comlet Out 2;
#P outlet 83 346 15 0;
#N comlet Out 1;
#P outlet 35 346 15 0;
#N comlet In 5;
#P inlet 376 42 15 0;
#N comlet In 4;
#P inlet 298 42 15 0;
#N comlet In 3;
#P inlet 220 42 15 0;
#N comlet In 2;
#P inlet 142 42 15 0;
#N comlet In 1;
#P inlet 35 42 15 0;
#P newex 289 281 534 196617 if \$i5 < \$i1 && \$i5 < \$i2 && \$i5 < \$i3 &&
\$i5 < \$i4 then 1 else 0;
#P newex 211 237 492 196617 if \$i4 < \$i1 && \$i4 < \$i2 && \$i4 < \$i3 &&
\$i4 < \$i5 then 1 else 0;
#P newex 156 192 440 196617 if \$i3 < \$i1 && \$i3 < \$i2 && \$i3 < \$i4 &&
\$i3 < \$i5 then 1 else 0;
#P newex 108 149 389 196617 if \$i2 < \$i1 && \$i2 < \$i3 && \$i2 < \$i4 &&
\$i2 < \$i5 then 1 else 0;
#P newex 64 102 325 196617 if \$i1 < \$i2 && \$i1 < \$i3 && \$i1 < \$i4 &&
\$i1 < \$i5 then 1 else 0;
#P fasten 0 0 10 0 69 336 40 336;
#P fasten 0 0 15 0 69 369 40 369;
#P connect 15 0 20 0;
#P connect 20 0 25 0;
#P fasten 25 0 30 0 40 456 40 456;
#P fasten 26 0 30 0 88 456 40 456;
#P fasten 27 0 30 0 136 456 40 456;
#P fasten 28 0 30 0 184 456 40 456;
#P fasten 29 0 30 0 232 456 40 456;
#P fasten 5 0 0 0 40 82 69 82;
#P lcolor 2;
#P fasten 1 0 11 0 113 337 88 337;
#P fasten 1 0 16 0 113 368 88 368;
#P connect 16 0 21 0;
#P connect 21 0 26 0;
#P fasten 5 0 1 0 40 143 113 143;
#P lcolor 2;
#P fasten 2 0 12 0 161 337 136 337;
#P fasten 2 0 17 0 161 367 136 367;
#P connect 17 0 22 0;
#P connect 22 0 27 0;
#P fasten 6 0 0 1 147 82 147 82;
#P lcolor 7;
#P fasten 5 0 2 0 40 186 161 186;
#P lcolor 2;
#P fasten 3 0 13 0 216 338 184 338;
#P fasten 3 0 18 0 216 370 184 370;
#P connect 18 0 23 0;
#P connect 23 0 28 0;
#P fasten 6 0 1 1 147 140 207 140;
#P lcolor 7;
#P fasten 5 0 3 0 40 229 216 229;
#P lcolor 2;
#P fasten 7 0 0 2 225 82 225 82;
#P lcolor 13;
#P fasten 4 0 14 0 294 336 232 336;
#P fasten 4 0 19 0 294 368 232 368;
#P connect 19 0 24 0;
#P connect 24 0 29 0;
#P fasten 6 0 2 1 147 181 268 181;
#P lcolor 7;
#P fasten 5 0 4 0 40 276 294 276;
#P lcolor 2;
#P fasten 7 0 1 2 225 140 301 140;
#P lcolor 13;
#P fasten 8 0 0 3 303 82 303 82;
#P lcolor 15;
#P fasten 6 0 3 1 147 227 336 227;
#P lcolor 7;
#P fasten 7 0 2 2 225 176 375 176;
#P lcolor 13;
#P fasten 9 0 0 4 381 82 381 82;
#P fasten 8 0 1 3 303 133 395 133;
#P lcolor 15;
#P fasten 6 0 4 1 147 271 425 271;
#P lcolor 7;
#P fasten 7 0 3 2 225 220 456 220;
#P lcolor 13;
#P fasten 8 0 2 3 303 172 482 172;
#P lcolor 15;
#P fasten 9 0 1 4 381 125 489 125;
#P fasten 7 0 4 2 225 266 556 266;
#P lcolor 13;
#P fasten 8 0 3 3 303 216 576 216;
#P lcolor 15;
#P fasten 9 0 2 4 381 169 589 169;
#P fasten 8 0 4 3 303 262 687 262;
#P lcolor 15;
#P fasten 9 0 3 4 381 213 696 213;
#P fasten 9 0 4 4 381 258 818 258;
#P pop;

On 20 Jan 2007, at 15:58, David Wright wrote:

>
> 2 years ago, I was writing a patcher in which I needed to determine
> which of 3 given numbers (with its index) was the largest. Eventually
> the manual reminded me about funbuffs, and I simply filled one with
> the 3 numbers and sent it the ‘max’ message. But until I came upon
> that easy solution, I was startled at the headaches this seemingly
> simple task was giving me, as a ‘pure’ MAX process. After more than a
> year of occasional work at it, this is the simplest solution I could
> find… and it’s still pretty Baroque. Maybe there’s something
> blindingly obvious I overlooked (aside from the funbuff workaround)…
> but I thought someone might be intrigued to find a simpler solution.
> I’m obviously still at a fairly elementary level.
>
> #P window setfont “Sans Serif” 9.;
> #P window linecount 2;
> #P comment 113 324 57 196617 Which of 3 is highest;
> #P comment 172 325 57 196617 Highest of 3 numbers;
> #P number 142 311 22 9 1 3 8359 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 178 312 37 9 0 0 8356 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P message 175 31 46 196617 13 8 21;
> #P message 138 31 34 196617 3 8 5;
> #P message 101 31 34 196617 0 1 2;
> #P newex 179 290 53 196617 switch 3;
> #P newex 186 268 49 196617 cycle 3;
> #P newex 187 249 61 196617 0 0 0;
> #P newex 187 227 24 196617 3;
> #P newex 142 270 27 196617 + 1;
> #P newex 185 161 23 196617 v g;
> #P newex 121 250 21 196617 v g;
> #P newex 89 138 46 196617 t clear i;
> #P newex 121 228 31 196617 sel;
> #P newex 123 208 27 196617 * 2;
> #P newex 127 188 22 196617 >;
> #P newex 139 161 44 196617 offer;
> #P newex 91 118 27 196617 >;
> #P newex 90 98 51 196617 route 1 0;
> #P newex 96 75 49 196617 funnel 2;
> #P newex 100 55 73 196617 cycle 3;
> #P message 64 216 29 196617 max;
> #N funbuff 0;
> #P newobj 63 232 42 196617 funbuff;
> #P window linecount 5;
> #P comment 7 168 114 196617 This is my 3rd version: if you can come up
> with a simpler one , please let me know… besides the obvious;
> #P fasten 11 1 7 0 130 158 144 158;
> #P fasten 11 1 13 0 130 155 190 155;
> #P connect 10 1 14 0;
> #P fasten 10 1 16 0 149 247 192 247;
> #P connect 10 0 12 0;
> #P fasten 10 0 15 0 163 226 192 226;
> #P connect 7 0 8 1;
> #P fasten 7 0 16 2 144 181 242 181;
> #P connect 4 0 5 0;
> #P fasten 4 0 7 0 98 95 144 95;
> #P fasten 3 2 8 0 167 185 132 185;
> #P fasten 3 2 16 1 217 158;
> #P connect 2 0 1 0;
> #P connect 6 0 11 0;
> #P connect 5 0 6 0;
> #P connect 3 0 4 0;
> #P fasten 21 0 3 0 180 51 105 51;
> #P fasten 20 0 3 0 143 51 105 51;
> #P fasten 19 0 3 0 106 51 105 51;
> #P connect 5 1 6 1;
> #P connect 9 0 10 0;
> #P connect 8 0 9 0;
> #P connect 3 1 4 1;
> #P fasten 11 0 7 0 94 159 144 159;
> #P fasten 12 0 14 0 126 269 147 269;
> #P connect 14 0 23 0;
> #P connect 18 0 22 0;
> #P connect 17 0 18 0;
> #P connect 16 0 17 0;
> #P connect 15 0 16 0;
> #P connect 17 1 18 2;
> #P connect 17 2 18 3;
> #P window clipboard copycount 26;
>
>
Gorwel Owen
http://www.rhwng.com/banjo.htm

#93843
Jan 23, 2007 at 11:30am

David Wright wrote:
> Wow, the board’s really hopping on this Saturday morning. 3 more
> replies came in even while I wrote my “Swiss Army” reply.Thanks for
> the brainpower, folks…

These kind of simple tasks are good for competition, who will come up
with the most elegant solution?
I’d add to that demand the rule, that only built-in objects should be
used, with additional points if it would run in Max 3.6/1.0 as well…

My contribution:
(if you skip the trigger it needs only two objects, but no extra points
for old Max versions, those go to Chris… ;-)

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 231 49 97 196617 103 8 21 4 8 9 101;
#P number 108 148 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 162 148 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 108 121 54 196617 zl sub;
#P newex 152 97 54 196617 maximum;
#P newex 108 75 54 196617 t l l;
#P message 182 49 46 196617 13 8 21;
#P message 145 49 34 196617 3 8 5;
#P message 108 49 34 196617 0 1 2;
#P fasten 8 0 3 0 236 69 113 69;
#P connect 4 0 5 1;
#P fasten 4 0 6 0 157 117 167 117;
#P connect 5 0 7 0;
#P connect 3 0 5 0;
#P connect 3 1 4 0;
#P fasten 1 0 3 0 150 69 113 69;
#P fasten 2 0 3 0 187 69 113 69;
#P connect 0 0 3 0;
#P window clipboard copycount 9;

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

#93844
Jan 24, 2007 at 7:02pm

#93845
Jan 26, 2007 at 5:32pm

jose manuel berenguer wrote:
> i’ve written a external that identifies the maximum and all of is

or one more object for the list…:

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 116 149 45 196617 zl group;
#P window linecount 0;
#P message 116 200 195 196617;
#P window linecount 1;
#P newex 116 177 62 196617 prepend set;
#P window linecount 2;
#P message 231 49 97 196617 103 8 21 4 103 8 9 101;
#P number 164 150 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 116 121 46 196617 zl sub;
#P newex 152 97 54 196617 maximum;
#P newex 108 75 54 196617 t b l l;
#P message 182 49 46 196617 13 8 21;
#P message 145 49 34 196617 3 8 5;
#P message 108 49 34 196617 0 1 2;
#P connect 4 0 5 1;
#P fasten 4 0 6 0 157 117 169 117;
#P connect 10 0 8 0;
#P fasten 3 0 10 0 113 144 121 144;
#P connect 3 1 5 0;
#P connect 3 2 4 0;
#P fasten 7 0 3 0 236 69 113 69;
#P fasten 1 0 3 0 150 69 113 69;
#P fasten 2 0 3 0 187 69 113 69;
#P connect 0 0 3 0;
#P connect 5 0 10 0;
#P connect 8 0 9 0;
#P window clipboard copycount 11;

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

#93846

You must be logged in to reply to this topic.