diff options
author | Ben Harris <ben@tilde.team> | 2019-12-08 01:56:33 -0500 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2019-12-08 01:56:33 -0500 |
commit | cd816151aaa58e6ffa3a7dac6c1e915cceeafca6 (patch) | |
tree | a1d6cf2b24dd9c028f1d96507431407a5fa461b7 /Day8.cs | |
parent | 270cac64a4005ffdbb17067d1583b646e6537ad8 (diff) |
day 8
Diffstat (limited to 'Day8.cs')
-rw-r--r-- | Day8.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Day8.cs b/Day8.cs new file mode 100644 index 0000000..aae6aa0 --- /dev/null +++ b/Day8.cs @@ -0,0 +1,39 @@ +using aoc2019.lib; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace aoc2019 +{ + internal class Day8 : Day + { + public override int DayNumber => 8; + + private readonly List<List<char>> photo; + public Day8() + { + photo = Input.First().Chunk(25 * 6).Select(s => s.ToList()).ToList(); + } + + public 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')}"; + } + + public 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'); + } + } +} |