Exemplo n.º 1
0
    public static void Part1(bool[,] lights)
    {
        var currentLights = AOC.Clone(lights);
        var newLights     = new bool[lights.GetLength(0), lights.GetLength(1)];

        for (int t = 0; t < 100; t++)
        {
            Step(currentLights, newLights);
            currentLights = AOC.Clone(newLights);
        }

        int count = 0;

        for (int x = 0; x < currentLights.GetLength(0); x++)
        {
            for (int y = 0; y < currentLights.GetLength(1); y++)
            {
                if (currentLights[x, y])
                {
                    count++;
                }
            }
        }

        Console.WriteLine(count);
    }
Exemplo n.º 2
0
    public static void Part2(bool[,] lights)
    {
        var currentLights = AOC.Clone(lights);
        int width         = currentLights.GetLength(0) - 1;
        int height        = currentLights.GetLength(1) - 1;

        currentLights[0, 0]          = true;
        currentLights[0, height]     = true;
        currentLights[width, 0]      = true;
        currentLights[width, height] = true;

        var newLights = new bool[lights.GetLength(0), lights.GetLength(1)];

        for (int t = 0; t < 100; t++)
        {
            Step(currentLights, newLights);
            currentLights                = AOC.Clone(newLights);
            currentLights[0, 0]          = true;
            currentLights[0, height]     = true;
            currentLights[width, 0]      = true;
            currentLights[width, height] = true;
        }

        int count = 0;

        for (int x = 0; x < currentLights.GetLength(0); x++)
        {
            for (int y = 0; y < currentLights.GetLength(1); y++)
            {
                if (currentLights[x, y])
                {
                    count++;
                }
            }
        }

        Console.WriteLine(count);
    }