Skip to content

Instantly share code, notes, and snippets.

@incon
Created December 9, 2017 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incon/6bb43b15bba8c84922173f53c1bf9566 to your computer and use it in GitHub Desktop.
Save incon/6bb43b15bba8c84922173f53c1bf9566 to your computer and use it in GitHub Desktop.
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