diff --git a/day15/input.txt b/day15/input.txt new file mode 100644 index 0000000..6472b57 --- /dev/null +++ b/day15/input.txt @@ -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. diff --git a/day15/input_2.txt b/day15/input_2.txt new file mode 100644 index 0000000..83e5290 --- /dev/null +++ b/day15/input_2.txt @@ -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. diff --git a/day15/part1.js b/day15/part1.js new file mode 100644 index 0000000..6e7c41e --- /dev/null +++ b/day15/part1.js @@ -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); diff --git a/day15/part2.js b/day15/part2.js new file mode 100644 index 0000000..0e60f36 --- /dev/null +++ b/day15/part2.js @@ -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);