Added day 15

This commit is contained in:
Tim Stallard 2016-12-15 10:39:21 +00:00
parent 3562208a14
commit e697150e0b
4 changed files with 57 additions and 0 deletions

6
day15/input.txt Normal file
View File

@ -0,0 +1,6 @@
Disc #1 has 17 positions; at time=0, it is at position 15.
Disc #2 has 3 positions; at time=0, it is at position 2.
Disc #3 has 19 positions; at time=0, it is at position 4.
Disc #4 has 13 positions; at time=0, it is at position 2.
Disc #5 has 7 positions; at time=0, it is at position 2.
Disc #6 has 5 positions; at time=0, it is at position 0.

7
day15/input_2.txt Normal file
View File

@ -0,0 +1,7 @@
Disc #1 has 17 positions; at time=0, it is at position 15.
Disc #2 has 3 positions; at time=0, it is at position 2.
Disc #3 has 19 positions; at time=0, it is at position 4.
Disc #4 has 13 positions; at time=0, it is at position 2.
Disc #5 has 7 positions; at time=0, it is at position 2.
Disc #6 has 5 positions; at time=0, it is at position 0.
Disc #7 has 11 positions; at time=0, it is at position 0.

22
day15/part1.js Normal file
View File

@ -0,0 +1,22 @@
var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
var cogs = input.split("\n").filter((a)=>(a)).map((line)=>{
var lineParts = line.match(/Disc #([1-9]+) has ([1-9]+) positions; at time=0, it is at position ([0-9]+)./);
return {
number: parseInt(lineParts[1]),
positions: parseInt(lineParts[2]),
startPos: parseInt(lineParts[3]),
};
}).sort((a, b)=>(a.number - b.number));
var t = -1;
var solved = false;
while(!solved){
solved = true;
t++;
for(var cog of cogs){
if(((cog.number + cog.startPos + t) % cog.positions) != 0){
solved = false;
}
}
}
console.log(t);

22
day15/part2.js Normal file
View File

@ -0,0 +1,22 @@
var input = require("fs").readFileSync("input_2.txt").toString().replace(/\r/g, "");
var cogs = input.split("\n").filter((a)=>(a)).map((line)=>{
var lineParts = line.match(/Disc #([1-9]+) has ([1-9]+) positions; at time=0, it is at position ([0-9]+)./);
return {
number: parseInt(lineParts[1]),
positions: parseInt(lineParts[2]),
startPos: parseInt(lineParts[3]),
};
}).sort((a, b)=>(a.number - b.number));
var t = -1;
var solved = false;
while(!solved){
solved = true;
t++;
for(var cog of cogs){
if(((cog.number + cog.startPos + t) % cog.positions) != 0){
solved = false;
}
}
}
console.log(t);