コード例 #1
0
        private static int FindPixelsOnAfter(string[] input, int steps)
        {
            var mappings = new Enhancements(input);
            var pattern  = ".#./..#/###".Split('/').ToCharMatrix();

            for (var loop = 0; loop < steps; loop++)
            {
                var w           = pattern.Width();
                var dim         = w % 2 == 0 ? 2 : 3;
                var newdim      = dim + 1;
                var n           = w / dim;       // n is number of new squares across or down (same number)
                var nextPattern = new char[n * newdim, n *newdim];
                for (var i = 0; i < n; i++)
                {
                    for (var j = 0; j < n; j++)
                    {
                        var part        = pattern.CopyPart(i * dim, j * dim, dim, dim);
                        var replacement = mappings.Enhance(part);
                        nextPattern.PastePart(i * newdim, j * newdim, replacement);
                    }
                }
                pattern = nextPattern;
            }

            var pixelsOn = pattern.CountChar('#');

            return(pixelsOn);
        }