Exemple #1
0
        public string Part2ComplexImage()
        {
            var input      = ReadInput();
            var imageBytes = input.StringToIntArray();
            var image      = new ComplexImage(Width, Height, imageBytes);

            var result = image.DecodeImage();

            var resultStirng = new StringBuilder();

            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    if (x == 0 && y != 0)
                    {
                        resultStirng.Append(Environment.NewLine);
                    }

                    resultStirng.Append((char)result[y, x]);
                }
            }

            return(resultStirng.ToString());
        }
Exemple #2
0
        public static int[,] DecodeImage(this ComplexImage img)
        {
            var result = new int[img.Height, img.Width];
            var colors = new int[] { 32, 35, 0 };

            for (int layer = 0; layer < img.Data.Length; layer++)
            {
                for (int x = 0; x < img.Width; x++)
                {
                    for (int y = 0; y < img.Height; y++)
                    {
                        if (result[y, x] == 0)
                        {
                            result[y, x] = colors[img.Data[layer][y][x]];
                        }
                    }
                }
            }

            return(result);
        }
Exemple #3
0
        public int Part1ComplexImage()
        {
            var image = new ComplexImage(Width, Height, _input);

            int zeros = Int32.MaxValue;
            int unoes = 0;
            int two   = 0;
            var tmp   = 0;

            for (int i = 0; i < image.Data.Length; i++)
            {
                tmp = UtilsDay8.NumberOf(image.Data[i], 0);
                if (tmp < zeros)
                {
                    zeros = tmp;
                    unoes = UtilsDay8.NumberOf(image.Data[i], 1);
                    two   = UtilsDay8.NumberOf(image.Data[i], 2);
                }
            }

            return(unoes * two);
        }