Added day 19 stuff (broken)
This commit is contained in:
parent
93823203f3
commit
9aba33b864
22
day19/part2.js
Normal file
22
day19/part2.js
Normal file
@ -0,0 +1,22 @@
|
||||
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);
|
30
day19/part2_2.js
Normal file
30
day19/part2_2.js
Normal file
@ -0,0 +1,30 @@
|
||||
var input = 3012210;
|
||||
|
||||
var elves = [];
|
||||
for(var i = 0; i < input; i++){
|
||||
elves[i] = true;
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
var count = elves.length;
|
||||
while(count > 1){
|
||||
if(!(count%1000)) console.log(count)
|
||||
var toRemoveAhead = Math.floor(count/2);
|
||||
var pos = i;
|
||||
var passed = 0;
|
||||
while(passed < toRemoveAhead){
|
||||
pos = (pos + 1)%(elves.length);
|
||||
if(elves[pos]){
|
||||
passed++;
|
||||
}
|
||||
}
|
||||
elves[pos] = false;
|
||||
count--;
|
||||
|
||||
i = (i+1)%(elves.length);
|
||||
while(elves[i] == false){
|
||||
i = (i+1)%(elves.length);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(elves.indexOf(true) + 1);
|
Loading…
x
Reference in New Issue
Block a user