day 6 and 7

This commit is contained in:
Tristan 2019-12-08 01:16:47 +00:00
parent dd9f13cb0d
commit cbc02f04d5
7 changed files with 2130 additions and 0 deletions

30
2019/06/part1.js Normal file
View file

@ -0,0 +1,30 @@
const fs = require("fs");
const text = fs.readFileSync("2019/06/input.txt", "utf-8");
let inputArr = text.split('\n');
let objNet = {};
let objArr = [];
inputArr.forEach(input => {
points = input.split(')');
objNet[points[1]] = points[0];
objArr.push(points[1]);
})
console.log(objNet);
total = 0;
let i;
objArr.forEach(obj => {
i=0
getOrigin(obj)
total+=i
});
console.log(total)
function getOrigin(obj) {
center = objNet[obj]
if (center) {
i++
return getOrigin(center)
} else {
return i
}
}