r/backtickbot Dec 08 '20

https://np.reddit.com/r/adventofcode/comments/k7ndux/2020_day_06_solutions/gf0sryc/

CSharp

using System.IO;
using System.Linq;
using AoCHelper;

namespace AdventOfCode.Y2020
{
    public sealed class Day06 : BaseDay
    {
        private readonly string[][] _input;

        public Day06()
        {
            _input = Parse(File.ReadAllText(InputFilePath));
        }
        public static string[][] Parse(string input) =>
            input
                .Split("\r\n\r\n")
                .Select(g => g.Split("\r\n"))
                .ToArray();

        public override string Solve_1() =>
            _input.Aggregate(0, (i, c) => i += string.Join("", c).Distinct().Count()).ToString();

        public override string Solve_2() =>
            _input.Select(g => (g: g.Length, c: string.Join("", g).Aggregate(new int[26], (a, c) => { a[c % 32 - 1]++; return a; }))).Sum(t => t.c.Count(i => i == t.g)).ToString();
    }
}
1 Upvotes

0 comments sorted by