adventofcode-2017/day12/part1.js

12 lines
346 B
JavaScript
Raw Permalink Normal View History

2017-12-16 12:12:56 +00:00
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);