comparing elements in array
Posted: Thu Mar 27, 2014 10:11 pm
I'm looking for an efficent solution for finding a single "peak" value within a small array (less than 50 elements). While I could do this with greens - at 25fps and some other stuff going on - I think ruby may be faster on that. Here it is what I exactly look for.
Let say that I have an array of floats, like this:
121
90
77
66
51
30
37
43
51
43
36
22
10
In above example - the peak is at index 8.
Concept:
- peak is a value at index N, greater than values at N-1 and N+1 indexes
- there will be only a one single peak in such array
- border values (lowest and highest) are never a peak values
- peak value does not have to be "max" in array (otherwise - it would be simple)
- it has to be efficient calculation (25fps or more), thus parsing the whole array per each comparison should not be done by greens, rather ruby.
Let say that I have an array of floats, like this:
121
90
77
66
51
30
37
43
51
43
36
22
10
In above example - the peak is at index 8.
Concept:
- peak is a value at index N, greater than values at N-1 and N+1 indexes
- there will be only a one single peak in such array
- border values (lowest and highest) are never a peak values
- peak value does not have to be "max" in array (otherwise - it would be simple)
- it has to be efficient calculation (25fps or more), thus parsing the whole array per each comparison should not be done by greens, rather ruby.