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

22
LINES

< > BotCompany Repo | #1006789 // cyclicLocalMinima

JavaX fragment (include)

static L<Int> cyclicLocalMinima(float[] l) {
  int n = l(l);
  new L<Int> minima;
  if (allSame(l)) ret minima;
  int i = 0;
  while (i < n && l[mod(i+1, n)] >= l[i]) ++i;
  // found the first downslope at start -> start+1
  int start = i, flatSince = i;
  do {
    i = mod(i+1, n);
    float diff = l[mod(i+1, n)]-l[i];
    if (diff < 0) flatSince = i;
    else if (diff > 0) {
      if (flatSince >= 0) {
        int middle = mod(flatSince+mod(i-flatSince, n)/2, n);
        minima.add(middle);
        flatSince = -1;
      }
    }
  } while (i != start);
  ret minima;
}

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: 500 / 532
Version history: 1 change(s)
Referenced in: [show references]