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

18
LINES

< > BotCompany Repo | #1017436 // combineZigZag - combine two priority-first lists into a new priority-first list

JavaX fragment (include)

static <A, B> L<Pair<A, B>> combineZigZag(L<A> l1, L<B> l2) {
  int lA = l(l1), lB = l(l2), maxSum = max(lA, lB);
  L<Pair<A, B>> out = new L;
  
  int ndiags = lA + lB - 1;
  for diag to ndiags: {
    int row_stop = max(0, diag - lA + 1);
    int row_start = min(diag, lB - 1);
    for (int row = row_start; row >= row_stop; row--) {
      // on a given diagonal row + col = constant "diag"
      // diag labels the diagonal number
      int col = diag - row;
      out.add(pair(l1.get(col), l2.get(row)));
    }
  }

  ret out;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017436
Snippet name: combineZigZag - combine two priority-first lists into a new priority-first list
Eternal ID of this version: #1017436/8
Text MD5: c59dcc56b90a333ca28eefaa48c78573
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-21 13:04:18
Source code size: 548 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 318 / 366
Version history: 7 change(s)
Referenced in: [show references]