Skip to content

Instantly share code, notes, and snippets.

@Nostromos
Last active July 8, 2025 17:21
Show Gist options
  • Save Nostromos/f6c150a8e2e14e3bdb1042a51f00970f to your computer and use it in GitHub Desktop.
Save Nostromos/f6c150a8e2e14e3bdb1042a51f00970f to your computer and use it in GitHub Desktop.
AoC 2017 - Day 9 - Mike Monaghan
import loadInput from "@/utils";
const PATH = "2017/Days/9/Input.txt"; // Relative to project root
const raw = loadInput(PATH);
const input = raw.split("")
// -----------------------------------------
// --- Day 9: Stream Processing ---
// -----------------------------------------
export function Day9(stream: string[]) {
let score = 0;
let garbage = false;
let depth = 0;
let garbageCount = 0;
for (let i = 0; i < stream.length; i++) {
let cur = stream[i];
if (!garbage) {
if (cur == '{') {
depth++;
} else if (cur == '}') {
score += depth
depth--;
} else if (cur == '<') {
garbage = true;
}
} else {
if (cur == '!') {
i++;
} else if (cur == '>') {
garbage = false;
} else {
garbageCount++;
}
}
}
return {
score: score,
garbage: garbageCount
};
}
console.log(Day9(input))
import loadInput from "@/utils";
const PATH = "2017/Days/9/Input.txt"; // Relative to project root
const raw = loadInput(PATH);
// -----------------------------------------
// --- Day 9: Stream Processing ---
// -----------------------------------------
export function Day9(stream: string) {
let score = 0;
let garbage = false;
let depth = 0;
let garbageCount = 0;
for (let i = 0; i < stream.length; i++) {
let cur = stream[i];
if (!garbage) {
if (cur == '{') {
depth++;
} else if (cur == '}') {
score += depth
depth--;
} else if (cur == '<') {
garbage = true;
}
} else {
if (cur == '!') {
i++;
} else if (cur == '>') {
garbage = false;
} else {
garbageCount++;
}
}
}
return {
score: score,
garbage: garbageCount
};
}
console.log(Day9(raw))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment