--- Day 14: Bathrooms ---

December 14

Listening to: N.U.D.E. | Liquid DnB / Jungle Mix


Have you ever bitten your tongue? Like super hard? Like, enough that it's numb and swolen for hours? That's my day today, and it sucks.


Anyway - moving robots, that's easy with the right definition.

private class Robot
{
    public int x, y, vx, vy;

    public Robot(string line) { /* parsing logic... */ }

    public void Move()
    {
        x = (x + vx) % WIDTH;
        y = (y + vy) % HEIGHT;

        if (x < 0) x += WIDTH;
        if (y < 0) y += HEIGHT;
    }
}

From there, just call Move() 100 times on each robot. Figuring out the "safety score" is a bit more involved than the actual movement, but not bad

private long GetSafetyScore(List<Robot> robots)
{
    int midWidth = WIDTH / 2;
    int midHeight = HEIGHT / 2;

    int upperLeft = 0, upperRight = 0, lowerLeft = 0, lowerRight = 0;

    foreach (var r in robots)
    {
        if (r.x < midWidth && r.y < midHeight) upperLeft++;
        else if (r.x < midWidth && r.y > midHeight) lowerLeft++;
        else if (r.x > midWidth && r.y < midHeight) upperRight++;
        else if (r.x > midWidth && r.y > midHeight) lowerRight++;
    }

    return upperLeft * upperRight * lowerLeft * lowerRight;
}

Ahahaha, okay this is going to be odd... I have to manually watch what's going on? So much for profiling this...

Okay, here's my thought: I don't know how long it will take, and it will likely take longer than is reasonable to manually check (source: I checked the first 100 seconds and it sucked). What if I just look for shapes? A long run of robots in a row should be a good indicator. First attempt is just look at a line of 10 robots in a row, and see what I get...

int maxRun = 0;
for (int i = 0; i < HEIGHT; i++)
{
    var curRun = 0;
    for (int j = 0; j < WIDTH; j++)
    {
        if (floor[i][j] == '.')
        {
            maxRun = Math.Max(curRun, maxRun);
            curRun = 0;
        }
        else
        {
            curRun++;
        }
    }
    maxRun = Math.Max(curRun, maxRun);
}

return maxRun > 10;

A tree

There it is! First try!


Time taken: 40 minutes

My solutions for today's puzzles