Make a ton of VS-recommended changes. Sure, why not.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
static void Main()
|
||||
{
|
||||
var start = System.DateTime.Now;
|
||||
Q01.Go();
|
||||
|
2
Q03.cs
2
Q03.cs
@ -25,7 +25,7 @@ namespace _2020
|
||||
list.Add(new List<bool>());
|
||||
for (int i = 0; i < line.Length; i++)
|
||||
{
|
||||
list[list.Count - 1].Add(line[i] != '.');
|
||||
list[^1].Add(line[i] != '.');
|
||||
}
|
||||
}
|
||||
|
||||
|
10
Q04.cs
10
Q04.cs
@ -7,11 +7,11 @@ namespace _2020
|
||||
{
|
||||
class Q04
|
||||
{
|
||||
static List<Dictionary<string, string>> Passports = new List<Dictionary<string, string>>();
|
||||
static readonly List<Dictionary<string, string>> Passports = new List<Dictionary<string, string>>();
|
||||
|
||||
static Regex PassportRegex = new Regex(@"(?<key>[a-z]{3}):(?<val>\S+)", RegexOptions.Compiled);
|
||||
static Regex HTMLColor = new Regex("^#[0-9a-f]{6}$", RegexOptions.Compiled);
|
||||
static Regex PassportID = new Regex("^[0-9]{9}$", RegexOptions.Compiled);
|
||||
static readonly Regex PassportRegex = new Regex(@"(?<key>[a-z]{3}):(?<val>\S+)", RegexOptions.Compiled);
|
||||
static readonly Regex HTMLColor = new Regex("^#[0-9a-f]{6}$", RegexOptions.Compiled);
|
||||
static readonly Regex PassportID = new Regex("^[0-9]{9}$", RegexOptions.Compiled);
|
||||
|
||||
public static void Go()
|
||||
{
|
||||
@ -35,7 +35,7 @@ namespace _2020
|
||||
var matches = PassportRegex.Matches(line);
|
||||
for (int i = 0; i < matches.Count; i++)
|
||||
{
|
||||
Passports[Passports.Count - 1].Add(matches[i].Groups["key"].Value, matches[i].Groups["val"].Value);
|
||||
Passports[^1].Add(matches[i].Groups["key"].Value, matches[i].Groups["val"].Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
Q06.cs
8
Q06.cs
@ -6,12 +6,12 @@ namespace _2020
|
||||
{
|
||||
class Q06
|
||||
{
|
||||
class group
|
||||
class Group
|
||||
{
|
||||
public int numInGroup;
|
||||
public Dictionary<char, int> answers;
|
||||
}
|
||||
static List<group> list = new List<group>();
|
||||
static readonly List<Group> list = new List<Group>();
|
||||
|
||||
public static void Go()
|
||||
{
|
||||
@ -25,12 +25,12 @@ namespace _2020
|
||||
using var fs = new FileStream("06input.txt", FileMode.Open);
|
||||
using var sr = new StreamReader(fs);
|
||||
string line;
|
||||
group entry = null;
|
||||
Group entry = null;
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
{
|
||||
if (line.Length == 0 || entry == null)
|
||||
{
|
||||
entry = new group()
|
||||
entry = new Group()
|
||||
{
|
||||
numInGroup = 0,
|
||||
answers = new Dictionary<char, int>(),
|
||||
|
8
Q07.cs
8
Q07.cs
@ -14,9 +14,9 @@ namespace _2020
|
||||
public List<Tuple<string, int>> ValidContents = new List<Tuple<string, int>>();
|
||||
}
|
||||
|
||||
static Regex bagRegex = new Regex(@"(?: contain |, )?(?<numBags>[0-9]+ )?(?<bagType>.+?) bags?", RegexOptions.Compiled);
|
||||
static readonly Regex bagRegex = new Regex(@"(?: contain |, )?(?<numBags>[0-9]+ )?(?<bagType>.+?) bags?", RegexOptions.Compiled);
|
||||
|
||||
static List<BagType> list = new List<BagType>();
|
||||
static readonly List<BagType> list = new List<BagType>();
|
||||
|
||||
public static void Go()
|
||||
{
|
||||
@ -82,11 +82,11 @@ namespace _2020
|
||||
|
||||
static void Part1()
|
||||
{
|
||||
Func<List<string>, BagType, List<string>> bagAgg = (accum, bagType) =>
|
||||
static List<string> bagAgg(List<string> accum, BagType bagType)
|
||||
{
|
||||
accum.Add(bagType.BagName);
|
||||
return accum;
|
||||
};
|
||||
}
|
||||
|
||||
var directContain = GetBagsCanContain(new BagType() { BagName = "shiny gold" });
|
||||
var totalContain = directContain.Aggregate(new List<string>(), bagAgg);
|
||||
|
4
Q08.cs
4
Q08.cs
@ -7,7 +7,7 @@ namespace _2020
|
||||
{
|
||||
class Q08
|
||||
{
|
||||
static List<Tuple<string, int>> instructions = new List<Tuple<string, int>>();
|
||||
static readonly List<Tuple<string, int>> instructions = new List<Tuple<string, int>>();
|
||||
|
||||
public static void Go()
|
||||
{
|
||||
@ -21,7 +21,7 @@ namespace _2020
|
||||
foreach (var line in File.ReadAllLines("08input.txt"))
|
||||
{
|
||||
var parts = line.Split(' ');
|
||||
if (parts.Count() != 2)
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
throw new Exception("malformed input");
|
||||
}
|
||||
|
2
Q09.cs
2
Q09.cs
@ -6,7 +6,7 @@ namespace _2020
|
||||
{
|
||||
class Q09
|
||||
{
|
||||
static List<long> list = new List<long>();
|
||||
static readonly List<long> list = new List<long>();
|
||||
|
||||
const int chunkLength = 25;
|
||||
|
||||
|
8
Q10.cs
8
Q10.cs
@ -6,7 +6,7 @@ namespace _2020
|
||||
{
|
||||
class Q10
|
||||
{
|
||||
static List<long> list = new List<long>();
|
||||
static readonly List<long> list = new List<long>();
|
||||
static List<long> sortedList = null;
|
||||
|
||||
public static void Go()
|
||||
@ -51,8 +51,10 @@ namespace _2020
|
||||
|
||||
static void Part2()
|
||||
{
|
||||
var pathsToIndices = new List<long>();
|
||||
pathsToIndices.Add(1);
|
||||
var pathsToIndices = new List<long>
|
||||
{
|
||||
1
|
||||
};
|
||||
for (int i = 1; i < sortedList.Count; i++)
|
||||
{
|
||||
long pathLen = 0;
|
||||
|
4
Q11.cs
4
Q11.cs
@ -100,7 +100,7 @@ namespace _2020
|
||||
{
|
||||
int numOccupied = 0;
|
||||
|
||||
Func<int, int, bool> checkSeat = (checkRow, checkCol) =>
|
||||
bool checkSeat(int checkRow, int checkCol)
|
||||
{
|
||||
if (seatList[checkRow, checkCol] == SeatState.Occupied)
|
||||
{
|
||||
@ -113,7 +113,7 @@ namespace _2020
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
// ul
|
||||
for (int checkRow = row - 1, checkCol = col - 1; checkRow >= 0 && checkCol >= 0; checkRow--, checkCol--)
|
||||
|
4
Q12.cs
4
Q12.cs
@ -18,7 +18,7 @@ namespace _2020
|
||||
static Vec2 waypointPosition = new Vec2() { x = 10, y = 1 };
|
||||
static int facingDir = 90;
|
||||
|
||||
static List<Tuple<char, int>> instructions = new List<Tuple<char, int>>();
|
||||
static readonly List<Tuple<char, int>> instructions = new List<Tuple<char, int>>();
|
||||
|
||||
public static void Go()
|
||||
{
|
||||
@ -119,7 +119,7 @@ namespace _2020
|
||||
}
|
||||
else if (dir == 'L')
|
||||
{
|
||||
facingDir = (facingDir - amount);
|
||||
facingDir -= amount;
|
||||
while (facingDir < 0)
|
||||
{
|
||||
facingDir = 360 + facingDir;
|
||||
|
4
Q13.cs
4
Q13.cs
@ -10,7 +10,7 @@ namespace _2020
|
||||
class Q13
|
||||
{
|
||||
static int leaveTime;
|
||||
static List<int> busses = new List<int>();
|
||||
static readonly List<int> busses = new List<int>();
|
||||
|
||||
public static void Go()
|
||||
{
|
||||
@ -116,7 +116,9 @@ namespace _2020
|
||||
}
|
||||
|
||||
// this is how i initially solved it. took ~30mins. i'm not proud of it, but the "real" answer apparently required specialized knowledge i did not have.
|
||||
#pragma warning disable IDE0051 // Remove unused private members
|
||||
static void Part2BruteForce()
|
||||
#pragma warning restore IDE0051 // Remove unused private members
|
||||
{
|
||||
int root = busses.First(x => x > 0);
|
||||
var sorted = busses.OrderBy(x => x);
|
||||
|
10
Q14.cs
10
Q14.cs
@ -21,7 +21,7 @@ namespace _2020
|
||||
public List<byte> mask = new List<byte>();
|
||||
public List<WriteInstruction> writeInstructions = new List<WriteInstruction>();
|
||||
}
|
||||
static List<Instruction> instructions = new List<Instruction>();
|
||||
static readonly List<Instruction> instructions = new List<Instruction>();
|
||||
|
||||
public static void Go()
|
||||
{
|
||||
@ -64,9 +64,11 @@ namespace _2020
|
||||
{
|
||||
var inst = instructions[^1];
|
||||
|
||||
var writeInst = new Instruction.WriteInstruction();
|
||||
writeInst.idx = Convert.ToUInt64(line["mem[".Length..line.IndexOf("]")]);
|
||||
writeInst.value = Convert.ToUInt64(line[(line.IndexOf('=') + 1)..]);
|
||||
var writeInst = new Instruction.WriteInstruction
|
||||
{
|
||||
idx = Convert.ToUInt64(line["mem[".Length..line.IndexOf("]")]),
|
||||
value = Convert.ToUInt64(line[(line.IndexOf('=') + 1)..])
|
||||
};
|
||||
|
||||
inst.writeInstructions.Add(writeInst);
|
||||
}
|
||||
|
2
Q15.cs
2
Q15.cs
@ -6,7 +6,7 @@ namespace _2020
|
||||
{
|
||||
class Q15
|
||||
{
|
||||
static List<int> list = new List<int>();
|
||||
static readonly List<int> list = new List<int>();
|
||||
|
||||
public static void Go()
|
||||
{
|
||||
|
15
Q18.cs
15
Q18.cs
@ -30,17 +30,12 @@ namespace _2020
|
||||
|
||||
static long DoOp(long left, long right, char op)
|
||||
{
|
||||
switch (op)
|
||||
return op switch
|
||||
{
|
||||
case '+':
|
||||
return left + right;
|
||||
|
||||
case '*':
|
||||
return left * right;
|
||||
|
||||
default:
|
||||
throw new Exception("unrecognized op");
|
||||
}
|
||||
'+' => left + right,
|
||||
'*' => left * right,
|
||||
_ => throw new Exception("unrecognized op"),
|
||||
};
|
||||
}
|
||||
|
||||
static void Part1()
|
||||
|
14
Q19.cs
14
Q19.cs
@ -7,8 +7,8 @@ namespace _2020
|
||||
{
|
||||
class Q19
|
||||
{
|
||||
static Dictionary<int, Rule> rules = new Dictionary<int, Rule>();
|
||||
static List<string> messages = new List<string>();
|
||||
static readonly Dictionary<int, Rule> rules = new Dictionary<int, Rule>();
|
||||
static readonly List<string> messages = new List<string>();
|
||||
|
||||
[DebuggerDisplay("ch={ch} | num rules={ruleIdxs?.Count}")]
|
||||
class Rule
|
||||
@ -141,8 +141,9 @@ namespace _2020
|
||||
|
||||
static void Part2()
|
||||
{
|
||||
var rulesUpdated = new Dictionary<int, Rule>(rules);
|
||||
rulesUpdated[8] = new Rule()
|
||||
var rulesUpdated = new Dictionary<int, Rule>(rules)
|
||||
{
|
||||
[8] = new Rule()
|
||||
{
|
||||
ruleIdxs = new List<List<int>>()
|
||||
{
|
||||
@ -156,8 +157,8 @@ namespace _2020
|
||||
8,
|
||||
},
|
||||
},
|
||||
};
|
||||
rulesUpdated[11] = new Rule()
|
||||
},
|
||||
[11] = new Rule()
|
||||
{
|
||||
ruleIdxs = new List<List<int>>()
|
||||
{
|
||||
@ -173,6 +174,7 @@ namespace _2020
|
||||
31,
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
int numMatched = 0;
|
||||
|
4
Q21.cs
4
Q21.cs
@ -8,8 +8,8 @@ namespace _2020
|
||||
{
|
||||
class Q21
|
||||
{
|
||||
static List<Tuple<List<string>, List<string>>> list = new List<Tuple<List<string>, List<string>>>();
|
||||
static Dictionary<string, int> ingredientCounts = new Dictionary<string, int>();
|
||||
static readonly List<Tuple<List<string>, List<string>>> list = new List<Tuple<List<string>, List<string>>>();
|
||||
static readonly Dictionary<string, int> ingredientCounts = new Dictionary<string, int>();
|
||||
static IEnumerable<string> allAllergens = new List<string>();
|
||||
static IEnumerable<string> allIngredients = new List<string>();
|
||||
|
||||
|
Reference in New Issue
Block a user