mirror of
https://github.com/jcreek/advent-of-code.git
synced 2026-07-12 18:53:47 +00:00
Add various uncommitted 2021 files for posterity
This commit is contained in:
@@ -56,12 +56,18 @@
|
||||
string secondHalf = line.Substring(line.IndexOf("|") + 1);
|
||||
List<string> numberSegments = secondHalf.Split(' ').ToList();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
string lineTotal = string.Empty;
|
||||
|
||||
foreach (string numberSegment in numberSegments)
|
||||
{
|
||||
// Go through sorted in alphabetical order
|
||||
string alphabetisedNumberSegment = String.Concat(numberSegment.OrderBy(c => c));
|
||||
Console.WriteLine(alphabetisedNumberSegment);
|
||||
|
||||
if(alphabetisedNumberSegment == String.Concat("acedgfb".OrderBy(c => c)))
|
||||
{
|
||||
@@ -103,6 +109,8 @@
|
||||
{
|
||||
lineTotal += "1";
|
||||
}
|
||||
|
||||
Console.WriteLine(lineTotal);
|
||||
}
|
||||
|
||||
Console.WriteLine(lineTotal);
|
||||
@@ -114,5 +122,45 @@
|
||||
|
||||
Console.WriteLine(total);
|
||||
}
|
||||
|
||||
static Dictionary<int, string> DetermineMapping(string[] lines)
|
||||
{
|
||||
Dictionary<int, string> mapping = new Dictionary<int, string>();
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string secondHalf = line.Substring(line.IndexOf("|") + 1);
|
||||
List<string> numberSegments = secondHalf.Split(' ').ToList();
|
||||
|
||||
foreach (string numberSegment in numberSegments)
|
||||
{
|
||||
switch (numberSegment.Length)
|
||||
{
|
||||
case 7:
|
||||
// 8 has only 7 segments/letters
|
||||
mapping.Add(8, numberSegment);
|
||||
break;
|
||||
case 3:
|
||||
// 7 has only 3 segments/letters
|
||||
mapping.Add(7, numberSegment);
|
||||
break;
|
||||
case 4:
|
||||
// 4 has only 4 segments/letters
|
||||
mapping.Add(4, numberSegment);
|
||||
break;
|
||||
case 2:
|
||||
// 1 has only 2 segments/letters
|
||||
mapping.Add(1, numberSegment);
|
||||
break;
|
||||
default:
|
||||
// handle the non-unique lengths (0,2,3,5,6,9)
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user