adventofcode-2017/day12/part1.js
2017-12-16 12:12:56 +00:00

12 lines
346 B
JavaScript

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);