Code formatting and warning fixing.
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>AdventOfCode2020</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>AdventOfCode2020</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="inputs\*">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="inputs\*">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AdventOfCode.Common\AdventOfCode.Common.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AdventOfCode.Common\AdventOfCode.Common.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -112,5 +112,4 @@ public class Day03 : IDay
|
||||
}
|
||||
return treeCnt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -118,7 +118,7 @@ iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719
|
||||
|
||||
Count the number of valid passports - those that have all required fields and valid values. Continue to treat cid as optional. In your batch file, how many passports are valid?
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
public class Day04 : IDay
|
||||
@@ -127,7 +127,7 @@ public class Day04 : IDay
|
||||
{
|
||||
List<Dictionary<string, string>> passports = Passports_Parse(inputs);
|
||||
int cnt = 0;
|
||||
List<string> neededFields = new() {
|
||||
List<string> neededFields = [
|
||||
"byr", // Birth Year
|
||||
"iyr", // Issue Year
|
||||
"eyr", // Expiration Year
|
||||
@@ -135,7 +135,7 @@ public class Day04 : IDay
|
||||
"hcl", // Hair Color
|
||||
"ecl", // Eye Color
|
||||
"pid", // Passport ID
|
||||
};
|
||||
];
|
||||
|
||||
foreach (Dictionary<string, string> passport in passports)
|
||||
{
|
||||
@@ -167,7 +167,7 @@ public class Day04 : IDay
|
||||
|
||||
private List<Dictionary<string, string>> Passports_Parse(string[] inputs)
|
||||
{
|
||||
List<Dictionary<string, string>> passports = new();
|
||||
List<Dictionary<string, string>> passports = [];
|
||||
Dictionary<string, string> passport = new();
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
@@ -257,5 +257,4 @@ public class Day04 : IDay
|
||||
if (input.All(char.IsNumber) == false) { return null; }
|
||||
return Convert.ToInt32(input);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -169,8 +169,8 @@ public class Day05 : IDay
|
||||
private Seat Seat_Parse(string input)
|
||||
{
|
||||
if (input.Length != 10 ||
|
||||
input.All(c => c == 'F' || c == 'B' || c == 'L' || c == 'R') == false ||
|
||||
false)
|
||||
input.All(c => c == 'F' || c == 'B' || c == 'L' || c == 'R') == false
|
||||
)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -67,10 +67,7 @@ public class Day06 : IDay
|
||||
|
||||
foreach (char c in input)
|
||||
{
|
||||
if (groupMap.ContainsKey(c) == false)
|
||||
{
|
||||
groupMap.Add(c, true);
|
||||
}
|
||||
groupMap.TryAdd(c, true);
|
||||
}
|
||||
}
|
||||
if (groupMap.Count > 0)
|
||||
@@ -78,7 +75,7 @@ public class Day06 : IDay
|
||||
groupMaps.Add(groupMap);
|
||||
}
|
||||
|
||||
int total = groupMaps.Sum(groupMap => groupMap.Count);
|
||||
int total = groupMaps.Sum(dict => dict.Count);
|
||||
return total.ToString();
|
||||
|
||||
}
|
||||
@@ -101,13 +98,9 @@ public class Day06 : IDay
|
||||
groupCount++;
|
||||
foreach (char c in input)
|
||||
{
|
||||
if (groupMap.ContainsKey(c) == false)
|
||||
if (groupMap.TryAdd(c, 1) == false)
|
||||
{
|
||||
groupMap.Add(c, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
groupMap[c] = groupMap[c] + 1;
|
||||
groupMap[c] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,15 +72,15 @@ public class Day07 : IDay
|
||||
{
|
||||
string myBagColor = "shiny gold";
|
||||
|
||||
List<BaggageRule> rules = new();
|
||||
List<BaggageRule> rules = [];
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
BaggageRule rule = BaggageRule_Parse(input);
|
||||
rules.Add(rule);
|
||||
}
|
||||
|
||||
List<string> bagColorsToCheck = new() { myBagColor };
|
||||
List<string> bagColorsChecked = new() { myBagColor };
|
||||
List<string> bagColorsToCheck = [myBagColor];
|
||||
List<string> bagColorsChecked = [myBagColor];
|
||||
int cntBagColors = 0;
|
||||
while (bagColorsToCheck.Count > 0)
|
||||
{
|
||||
@@ -108,7 +108,7 @@ public class Day07 : IDay
|
||||
{
|
||||
string myBagColor = "shiny gold";
|
||||
|
||||
List<BaggageRule> rules = new();
|
||||
List<BaggageRule> rules = [];
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
BaggageRule rule = BaggageRule_Parse(input);
|
||||
@@ -116,30 +116,31 @@ public class Day07 : IDay
|
||||
}
|
||||
Dictionary<string, BaggageRule> dictRules = rules.ToDictionary(x => x.BagColor);
|
||||
|
||||
int cnt = BaggageRule_CountChilds(myBagColor, dictRules);
|
||||
int cnt = BaggageRule_CountChildren(myBagColor, dictRules);
|
||||
|
||||
return cnt.ToString();
|
||||
}
|
||||
|
||||
public class BaggageContainRule
|
||||
private class BaggageContainRule
|
||||
{
|
||||
public string BagColor { get; set; }
|
||||
public int Count { get; set; }
|
||||
public int Count { get; init; }
|
||||
}
|
||||
|
||||
public class BaggageRule
|
||||
private class BaggageRule
|
||||
{
|
||||
public string BagColor { get; set; }
|
||||
|
||||
public List<BaggageContainRule> Contain { get; set; }
|
||||
public List<BaggageContainRule> Contain { get; init; }
|
||||
}
|
||||
|
||||
public BaggageRule BaggageRule_Parse(string input)
|
||||
private BaggageRule BaggageRule_Parse(string input)
|
||||
{
|
||||
string[] words = input.Split(' ');
|
||||
string status = "Parse Color 1";
|
||||
BaggageRule rule = new();
|
||||
rule.Contain = new List<BaggageContainRule>();
|
||||
BaggageRule rule = new() {
|
||||
Contain = [],
|
||||
};
|
||||
BaggageContainRule containRule = null;
|
||||
string color1 = string.Empty;
|
||||
|
||||
@@ -164,9 +165,14 @@ public class Day07 : IDay
|
||||
status = "Parse Contain count";
|
||||
break;
|
||||
case "Parse Contain count":
|
||||
if (word == "no") { status = "End"; break; }
|
||||
containRule = new BaggageContainRule();
|
||||
containRule.Count = Convert.ToInt32(word);
|
||||
if (word == "no")
|
||||
{
|
||||
status = "End";
|
||||
break;
|
||||
}
|
||||
containRule = new BaggageContainRule {
|
||||
Count = Convert.ToInt32(word),
|
||||
};
|
||||
status = "Parse Contain color 1";
|
||||
break;
|
||||
case "Parse Contain color 1":
|
||||
@@ -179,7 +185,11 @@ public class Day07 : IDay
|
||||
status = "Parse Contain continue";
|
||||
break;
|
||||
case "Parse Contain continue":
|
||||
if (word == "bag," || word == "bags,") { status = "Parse Contain count"; break; }
|
||||
if (word == "bag," || word == "bags,")
|
||||
{
|
||||
status = "Parse Contain count";
|
||||
break;
|
||||
}
|
||||
status = "End";
|
||||
break;
|
||||
case "End":
|
||||
@@ -189,13 +199,13 @@ public class Day07 : IDay
|
||||
return rule;
|
||||
}
|
||||
|
||||
public int BaggageRule_CountChilds(string color, Dictionary<string, BaggageRule> dictRules)
|
||||
private int BaggageRule_CountChildren(string color, Dictionary<string, BaggageRule> dictRules)
|
||||
{
|
||||
int cnt = 0;
|
||||
BaggageRule rule = dictRules[color];
|
||||
foreach (BaggageContainRule containRule in rule.Contain)
|
||||
{
|
||||
cnt += (BaggageRule_CountChilds(containRule.BagColor, dictRules) + 1) * containRule.Count;
|
||||
cnt += (BaggageRule_CountChildren(containRule.BagColor, dictRules) + 1) * containRule.Count;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -124,14 +124,14 @@ public class Day08 : IDay
|
||||
return vm.Accumulator.ToString();
|
||||
}
|
||||
|
||||
public enum OpCode
|
||||
private enum OpCode
|
||||
{
|
||||
Acc,
|
||||
Jmp,
|
||||
Nop,
|
||||
}
|
||||
|
||||
public class Instruction
|
||||
private class Instruction
|
||||
{
|
||||
public OpCode OpCode { get; set; }
|
||||
public int Value { get; set; }
|
||||
@@ -154,14 +154,9 @@ public class Day08 : IDay
|
||||
OpCode = OpCode.Nop;
|
||||
}
|
||||
|
||||
if (parts[1].StartsWith("+"))
|
||||
{
|
||||
Value = Convert.ToInt32(parts[1].Substring(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Value = Convert.ToInt32(parts[1]);
|
||||
}
|
||||
Value = Convert.ToInt32(parts[1].StartsWith("+")
|
||||
? parts[1].Substring(1)
|
||||
: parts[1]);
|
||||
Executed = false;
|
||||
}
|
||||
}
|
||||
@@ -176,7 +171,7 @@ public class Day08 : IDay
|
||||
|
||||
public VM(string[] inputs)
|
||||
{
|
||||
Instructions = new List<Instruction>();
|
||||
Instructions = [];
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
Instructions.Add(new Instruction(input));
|
||||
|
||||
@@ -163,5 +163,4 @@ public class Day09 : IDay
|
||||
|
||||
return firstInvalid;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user