Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #1006789 // cyclicLocalMinima

JavaX fragment (include)

1  
static L<Int> cyclicLocalMinima(float[] l) {
2  
  int n = l(l);
3  
  new L<Int> minima;
4  
  if (allSame(l)) ret minima;
5  
  int i = 0;
6  
  while (i < n && l[mod(i+1, n)] >= l[i]) ++i;
7  
  // found the first downslope at start -> start+1
8  
  int start = i, flatSince = i;
9  
  do {
10  
    i = mod(i+1, n);
11  
    float diff = l[mod(i+1, n)]-l[i];
12  
    if (diff < 0) flatSince = i;
13  
    else if (diff > 0) {
14  
      if (flatSince >= 0) {
15  
        int middle = mod(flatSince+mod(i-flatSince, n)/2, n);
16  
        minima.add(middle);
17  
        flatSince = -1;
18  
      }
19  
    }
20  
  } while (i != start);
21  
  ret minima;
22  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006789
Snippet name: cyclicLocalMinima
Eternal ID of this version: #1006789/2
Text MD5: a3b84fed8af39a4318ca78fa2047afd6
Author: stefan
Category: javax / maths
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-04 04:49:11
Source code size: 595 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 502 / 534
Version history: 1 change(s)
Referenced in: [show references]