diff options
Diffstat (limited to 'Day08.cs')
-rw-r--r-- | Day08.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Day08.cs b/Day08.cs new file mode 100644 index 0000000..94cd461 --- /dev/null +++ b/Day08.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using aoc2019.lib; + +namespace aoc2019 +{ + internal sealed class Day08 : Day + { + private readonly List<List<char>> photo; + + public Day08() : base(8, "Space Image Format") + { + photo = Input.First().Chunk(25 * 6).Select(s => s.ToList()).ToList(); + } + + protected override string Part1() + { + var l = photo.OrderBy(layer => layer.Count(pixel => pixel == '0')).First(); + return $"{l.Count(p => p == '1') * l.Count(p => p == '2')}"; + } + + protected override string Part2() + { + return Enumerable.Range(0, 25 * 6) + .Select(p => Enumerable.Range(0, photo.Count) + .Select(l => photo[l][p]) + .Aggregate('2', (acc, next) => + acc != '2' ? acc : next == '0' ? ' ' : next + ) + ) + .ToDelimitedString() + .Chunk(25) + .ToDelimitedString(Environment.NewLine) + .Replace('1', 'x'); + } + } +} \ No newline at end of file |