Created
December 9, 2017 06:47
-
-
Save incon/6bb43b15bba8c84922173f53c1bf9566 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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