Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let data = require("fs").readFileSync("day9-input.txt", "UTF-8");
let garbage = 0;
let total = 0;
let canceled = false;
let ignore = false;
let depth = 0;
data.split("").forEach(char => {
if (ignore) {
if (canceled) {
canceled = false;
return;
}
if (char === ">") {
ignore = false;
return;
}
if (char === "!") {
canceled = true;
return;
}
garbage++;
return;
}
switch (char) {
case "<":
ignore = true;
break;
case "{":
depth++;
break;
case "}":
total += depth;
depth--;
break;
}
});
console.log("Part 1:", total);
console.log("Part 2:", garbage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.