Skip to content

Instantly share code, notes, and snippets.

@odaba
Created June 15, 2015 10:43
Show Gist options
  • Save odaba/48425c8fcc0cf327f37c to your computer and use it in GitHub Desktop.
Save odaba/48425c8fcc0cf327f37c to your computer and use it in GitHub Desktop.
code warriors 551dd1f424b7a4cdae0001f0
function whoIsNext(names, r){
var x = names.length;
var pass = ((r - 1)/x) + 1;
var cycle = Math.log(pass)/Math.LN2;
var grouping = Math.pow(2, Math.floor(cycle));
var cbegin = (grouping - 1) * x;
var r_offset = r - cbegin - 1;
var r_index = Math.floor(r_offset / grouping);
return [x, pass, cycle, grouping, cbegin, r_offset, r_index, names[r_index]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment