// See https://aka.ms/new-console-template for more information

var lines = File.ReadAllLines("day3.txt");
var total = 0;
for (int i = 0; i < lines.Length; i+=3)
{
    total += GetPriority(GetBadge(lines, i));
}

Console.WriteLine(total);

char GetBadge(string[] strings, int index)
{
    var set1 = new HashSet<char>();
    foreach (var c in strings[index])
    {
        set1.Add(c);
    }

    var set2 = new HashSet<char>();
    foreach (var c in strings[index + 1])
    {
        if (set1.Contains(c))
            set2.Add(c);
    }

    foreach (var c in strings[index + 2])
    {
        if (set2.Contains(c))
        {
            Console.WriteLine(c);
            return c;
        }
    }

    throw new InvalidOperationException();
}

int GetPriority(char c) =>
    c switch
    {
        >= 'a' and <= 'z' => c - 'a' + 1,
        >= 'A' and <= 'Z' => c - 'A' + 27,
        _ => throw new InvalidOperationException()
    };