23 lines
423 B
JavaScript
23 lines
423 B
JavaScript
|
var input = 7;
|
||
|
|
||
|
var elves = [];
|
||
|
for(var i = 0; i < input; i++){
|
||
|
elves.push(i+1);
|
||
|
}
|
||
|
|
||
|
var i = 0;
|
||
|
while(elves.length > 1){
|
||
|
if(!(elves.length%1000)) console.log(elves.length)
|
||
|
var toRemove = Math.floor((i + (elves.length/2)))%(elves.length)
|
||
|
//console.log(i, elves[i], elves[toRemove], elves);
|
||
|
elves.splice(toRemove, 1);
|
||
|
if(toRemove > i){
|
||
|
i = (i+1)%elves.length;
|
||
|
}
|
||
|
else{
|
||
|
i = i%elves.length;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
console.log(elves);
|