adventofcode-2017/day09/part1.js
2017-12-09 14:12:59 +00:00

7 lines
382 B
JavaScript

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