Пример #1
0
    public void Solve(ReadOnlySpan <byte> input, Solution solution)
    {
        var grid = new Day24Grid();

        PopulateInitialBlackTiles(input, grid);

        int part1 = grid.AliveCount;

        for (int i = 0; i < 100; i++)
        {
            grid.Step();
        }

        int part2 = grid.AliveCount;

        solution.SubmitPart1(part1);
        solution.SubmitPart2(part2);
    }
Пример #2
0
    private static void PopulateInitialBlackTiles(ReadOnlySpan <byte> input, Day24Grid grid)
    {
        int q = 128;
        int r = 128;

        int i = 0;

        while (i < input.Length)
        {
            byte c = input[i++];
            switch (c)
            {
            case (byte)'\n':
                grid.FlipTile(q, r);
                q = 128;
                r = 128;
                break;

            case (byte)'w':
                q--;
                break;

            case (byte)'e':
                q++;
                break;

            case (byte)'n':
                r--;
                if (input[i++] == 'e')
                {
                    q++;
                }
                break;

            case (byte)'s':
                r++;
                if (input[i++] == 'w')
                {
                    q--;
                }
                break;
            }
        }
    }