29 lines
1.0 KiB
C#
29 lines
1.0 KiB
C#
namespace AdventOfCodeLibrary._2022
|
|
{
|
|
using AdventOfCodeLibrary.Shared;
|
|
|
|
public class Day03Part1 : IAnswerable
|
|
{
|
|
public int Year { get; set; } = 2022;
|
|
public int Day { get; set; } = 3;
|
|
public int Part { get; set; } = 1;
|
|
|
|
public string GetAwner(byte[] data)
|
|
{
|
|
string[] rucksackData = ByteHelper.GetAsStringArray(data);
|
|
int priorityCount = 0;
|
|
|
|
// go throu each ruchsack
|
|
foreach (string rucksack in rucksackData.Where(x => !string.IsNullOrWhiteSpace(x)))
|
|
{
|
|
// split the data line down the middel
|
|
string rucksackOne = rucksack.Substring(0, rucksack.Length / 2);
|
|
string rucksackTwo = rucksack.Substring(rucksack.Length / 2, rucksack.Length / 2);
|
|
char prioChar = rucksackOne.Where(x => rucksackTwo.Contains(x)).First();
|
|
priorityCount += prioChar > 'Z' ? (prioChar - 'a' + 1) : (prioChar - 'A' + 27);
|
|
}
|
|
|
|
return priorityCount.ToString();
|
|
}
|
|
}
|
|
} |