29 lines
959 B
C#
29 lines
959 B
C#
namespace AdventOfCodeLibrary._2022
|
|
{
|
|
using AdventOfCodeLibrary.Shared;
|
|
|
|
public class Day03Part2 : IAnswerable
|
|
{
|
|
public int Year { get; set; } = 2022;
|
|
public int Day { get; set; } = 3;
|
|
public int Part { get; set; } = 2;
|
|
|
|
public string GetAwner(byte[] data)
|
|
{
|
|
string[] rucksackData = ByteHelper.GetAsStringArray(data);
|
|
int priorityCount = 0;
|
|
|
|
// go throu each ruchsack
|
|
for (int index = 0; index < rucksackData.Length; index += 3)
|
|
{
|
|
// get the 3 ruchsacks
|
|
string[] ruchsacks = rucksackData.Skip(index).Take(3).ToArray();
|
|
char prioChar = ruchsacks[0].Where(x => ruchsacks[1].Contains(x) && ruchsacks[2].Contains(x)).First();
|
|
priorityCount += prioChar > 'Z' ? (prioChar - 'a' + 1) : (prioChar - 'A' + 27);
|
|
}
|
|
|
|
return priorityCount.ToString();
|
|
}
|
|
}
|
|
}
|