[PD] Index of the maximum value in a list

Lorenzo Sutton lorenzofsutton at gmail.com
Wed Apr 15 13:12:56 CEST 2015


On 14/04/2015 01:00, Pierre Desprats wrote:
> Hi,
>
> it would be really helpfull if someone had patched something to obtain
> the index of the maximum value in a list,
>
> Or maybe a [max] object with more than 2 inputs ?

The attached hacks the sequencer example from the [list] help. Clearly 
it could be made a bit prettier and turned into an abstraction...

Hope it helps.

Lorenzo.
-------------- next part --------------
#N canvas 354 110 792 570 10;
#X obj 123 109 list split 1, f 18;
#X obj 186 166 list append;
#X obj 123 230 t f b, f 6;
#X msg 550 113 0;
#X obj 564 306 f;
#X obj 597 306 + 1;
#X obj 334 452 spigot;
#X msg 122 2 20 22 -3 4 100 6 8 200;
#X obj 407 516 print index_of_greatest;
#X msg 294 2 1000 -50 20 12200 500;
#X msg 463 2 1 4 3 2;
#X obj 198 363 spigot;
#X obj 284 166 del 1;
#X obj 407 493 f, f 12;
#X msg 544 2 5 4 3 2 1;
#X obj 550 137 t f f;
#X obj 123 206 pipe 0.001;
#X obj 333 366 pipe;
#X obj 124 252 t f f f b;
#X obj 123 56 t l l b;
#X obj 313 109 list split 1;
#X obj 353 166 t f;
#X msg 626 2 -3 -6 -100 -2 -5;
#X obj 124 406 f, f 4;
#X obj 124 517 print greatest;
#X obj 284 193 t b b, f 18;
#X text 600 123 reset counter and index to 0, f 16;
#X text 631 290 counter - i.e. list index, f 11;
#X text 509 442 Hold the current index of the greatest number. This
is 0 at the beginning and increases only if a larger number is found
, f 25;
#X text -13 135 Taken from the sequenccer example in the [list] help
, f 18;
#X text 377 54 First element in list will be the first to be compared
, f 20;
#X text 427 97 |;
#X text 405 108 <--+;
#X msg -4 0 1 2 2 0 2 2 0;
#X obj 237 331 >=, f 17;
#X text -6 -28 In this case the last is taken, f 17;
#X text 311 486 This [f] is banged at the end, f 11;
#X text -13 293 Is current number >= than the previous? If TRUE: \;
1 let its index pas and 2 make it the new number to compare against
, f 15;
#X connect 0 0 16 0;
#X connect 0 1 1 1;
#X connect 0 2 12 0;
#X connect 1 0 0 0;
#X connect 2 0 18 0;
#X connect 2 1 1 0;
#X connect 3 0 15 0;
#X connect 4 0 5 0;
#X connect 4 0 17 0;
#X connect 5 0 4 1;
#X connect 6 0 13 1;
#X connect 7 0 19 0;
#X connect 9 0 19 0;
#X connect 10 0 19 0;
#X connect 11 0 23 1;
#X connect 11 0 34 1;
#X connect 12 0 25 0;
#X connect 13 0 8 0;
#X connect 14 0 19 0;
#X connect 15 0 13 1;
#X connect 15 1 4 1;
#X connect 16 0 2 0;
#X connect 17 0 6 0;
#X connect 18 0 11 0;
#X connect 18 1 34 0;
#X connect 18 3 4 0;
#X connect 19 0 0 0;
#X connect 19 1 20 0;
#X connect 19 2 3 0;
#X connect 20 1 21 0;
#X connect 21 0 34 1;
#X connect 22 0 19 0;
#X connect 23 0 24 0;
#X connect 25 0 23 0;
#X connect 25 1 13 0;
#X connect 33 0 19 0;
#X connect 34 0 6 1;
#X connect 34 0 11 1;


More information about the Pd-list mailing list