day 9
This commit is contained in:
parent
e9e4c7a9cc
commit
3b686f4759
1
day09/input.txt
Normal file
1
day09/input.txt
Normal file
File diff suppressed because one or more lines are too long
6
day09/part1.js
Normal file
6
day09/part1.js
Normal file
@ -0,0 +1,6 @@
|
||||
var input = require("fs").readFileSync("input.txt").toString();
|
||||
var nogarbage = input.replace(/!./g, "").replace(/<[^>]*>/g, "");
|
||||
var json = nogarbage.replace(/{/g, "[").replace(/}/g, "]").replace(/\[[,]+/g, "[").replace(/[,]+\]/g, "]");
|
||||
var structure = JSON.parse(json);
|
||||
score = (o, d)=>(o.map((c)=>(score(c, d+1))).reduce((a, b)=>(a+b), 0) + d);
|
||||
console.log(score(structure, 1));
|
13
day09/part2.js
Normal file
13
day09/part2.js
Normal file
@ -0,0 +1,13 @@
|
||||
var input = require("fs").readFileSync("input.txt").toString();
|
||||
var cancelled = input.replace(/!./g, "");
|
||||
var garbage = [];
|
||||
var match = null;
|
||||
var regex = new RegExp("<([^>]*)>", "g");
|
||||
do{
|
||||
match = regex.exec(cancelled);
|
||||
if(match){
|
||||
garbage.push(match[1]);
|
||||
}
|
||||
}
|
||||
while(match != null);
|
||||
console.log(garbage.map((a)=>(a.length)).reduce((a, b)=>(a+b)));
|
Loading…
x
Reference in New Issue
Block a user