--- Day 10: Something something Lisp ---

December 10

Listening to: Future Funk


This one seems like Lisp. At least, in the sense that it's matching a lot of open and close pairs of different kinds, and matching them up. More particularly, figuring out the lines where this is false. Not difficult, but maybe a bit tricky with having four different pairs of characters to deal with.

for (auto c: line) {
    if (open.find(c) != string::npos) {
        chunks.push(c);
    } else {
        // Chunk Valid
        if (open.find(chunks.top()) == closed.find(c)) {
            chunks.pop();
        }
        // Chunk Invalid
        else {
            score += points[closed.find(c)];
            cout << "Chunk error! [" << c << "] Total points: \t" << score << "\n";
            break;
        }

    }
}

This was pretty easy with part one. With the corrupt chunks missing, all the remaining are incomplete. Since I was already keeping the remaining chunk openings in a stack, I just have to pop from the top of the stack to create the closing parts of the chunks, and tally up the score.

int lineScore = 0;
while (!chunks.empty()) {
    int i = open.find(chunks.top());
    chunks.pop();

    lineScore *= 5;
    lineScore += points[i];
}

scores.push_back(lineScore);

Once again, numbers got long enough that I had to use a long long instead of an int.

I also accidentally kept the scores of the corrupted lines in at the end... which... unfortunately broke things. Ugh.


My solutions for today's puzzles