Esempio n. 1
0
        public override void First()
        {
            var img          = new SiImage("Day8/image.txt", 25, 6);
            var minzerolayer = img.layers
                               .Select(l => new { layer = l, zeroes = l.Where(p => p == '0').Count() })
                               .OrderBy(l => l.zeroes).First().layer;
            var onesandtwos = minzerolayer.Count(l => l == '1') * minzerolayer.Count(l => l == '2');

            Echo($"#1s * #2s: {onesandtwos}");
            ValidateAnswer(onesandtwos, 1742);
        }
Esempio n. 2
0
        public override void Second()
        {
            var img    = new SiImage("Day8/image.txt", 25, 6);
            var merged = new char[img.width * img.height];

            for (int i = 0; i < img.width * img.height; i++)
            {
                foreach (var layer in img.layers)
                {
                    merged[i] = layer[i];
                    if (layer[i] == '1' || layer[i] == '0')
                    {
                        break;
                    }
                }
            }
            for (int i = 0; i < img.height; i++)
            {
                Echo($"{merged.Skip(i * img.width).Take(img.width).Aggregate("", (str, c) => str+(c=='0'?' ':'*'))}");
            }
        }