adventofcode-2016/day19/part2.js

23 lines
423 B
JavaScript
Raw Normal View History

2016-12-20 15:10:11 +00:00
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);