days 11-16
This commit is contained in:
2000
day12/input.txt
Normal file
2000
day12/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
11
day12/part1.js
Normal file
11
day12/part1.js
Normal file
@ -0,0 +1,11 @@
|
||||
var input = require("fs").readFileSync("input.txt").toString();
|
||||
var links = input.split("\n").filter((a)=>(a)).map((a)=>(a.split(" <-> ")[1].split(", ").map((b)=>(parseInt(b)))));
|
||||
var attached = [];
|
||||
function add(x){
|
||||
if(attached.indexOf(x) == -1){
|
||||
attached.push(x);
|
||||
links[x].forEach((a)=>(add(a)));
|
||||
}
|
||||
}
|
||||
add(0);
|
||||
console.log(attached.length);
|
19
day12/part2.js
Normal file
19
day12/part2.js
Normal file
@ -0,0 +1,19 @@
|
||||
var input = require("fs").readFileSync("input.txt").toString();
|
||||
var links = input.split("\n").filter((a)=>(a)).map((a)=>(a.split(" <-> ")[1].split(", ").map((b)=>(parseInt(b)))));
|
||||
var allvisited = [];
|
||||
function getconnected(x, items){
|
||||
if(items.indexOf(x) == -1){
|
||||
items.push(x);
|
||||
links[x].forEach((a)=>(getconnected(a, items)));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
var i = 0;
|
||||
while(allvisited.length != Object.keys(links).length){
|
||||
var start = Object.keys(links).map((a)=>(parseInt(a))).filter((a)=>(allvisited.indexOf(a) == -1))[0];
|
||||
console.log(i, start);
|
||||
var newgroup = getconnected(start, []);
|
||||
allvisited = allvisited.concat(newgroup);
|
||||
i++
|
||||
}
|
||||
console.log(i);
|
Reference in New Issue
Block a user