--- Day 2: Diving and Driving ---

December 2

Listening to: Synthwave


Okay, I started a day late. So I did yesterday's only a few minutes before trying this. And I guess the 'next day' is 9pm my time, so I might even try tomorrows today as well.

It looks like today's involves processing words and numbers together as commands. Still pretty simple in general, but for C++ I guess it's a little more tricky because of string processing? I'm not sure.

int depth = 0, pos = 0, dist;
string line, val;

while (std::getline(input, line, ' '))
{
    std::getline(input, val, '\n');
    dist = stoi(val);

    if (line == "forward")      pos += dist;
    else if (line == "down")    depth += dist;
    else if (line == "up")      depth -= dist;
}

I REALLY want to be able to use a switch for this. It's such an obvious case for a switch statement - there's a few discrete options that I want to handle, with different results on each one. Ugh! If statements everywhere. I guess.


Huh, neat. The whole thing is basically a little story of how you're learning to use equipment. This is really cute. A few modifications to the 'if' statements and a new value to keep track of, and the logic changes were pretty trivial

if (line == "down")             aim += val;
else if (line == "up")          aim -= val;
else if (line == "forward") {   pos += val; depth += aim * val; }

On top of that, it looks like day three has just released. And the leaderboards have already filled up, ahahaha. I guess I'll have to be on the ball at 9pm to try and solve this more quickly!


My solutions for today's puzzles