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:
@@ -8,4 +8,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="input.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-10
@@ -1,10 +1 @@
|
||||
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
|
||||
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
|
||||
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg
|
||||
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb
|
||||
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea
|
||||
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb
|
||||
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe
|
||||
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef
|
||||
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb
|
||||
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce
|
||||
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
|
||||
Reference in New Issue
Block a user