WIP Apply nullability
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>AdventOfCode.Common</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode.Common</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2017.Tests</RootNamespace>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2017</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -30,11 +30,11 @@ public class Day03 : IDay
|
||||
{
|
||||
public string ResolvePart1(string[] inputs)
|
||||
{
|
||||
return null;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string ResolvePart2(string[] inputs)
|
||||
{
|
||||
return null;
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,11 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2018.Tests</RootNamespace>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2018</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public class Day01 : IDay
|
||||
public string ResolvePart2(string[] inputs)
|
||||
{
|
||||
int accumulator = 0;
|
||||
List<int> accumulatorHistory = new();
|
||||
List<int> accumulatorHistory = [];
|
||||
int? repeatedAccumulator = null;
|
||||
while (repeatedAccumulator == null)
|
||||
{
|
||||
@@ -108,6 +108,6 @@ public class Day01 : IDay
|
||||
}
|
||||
}
|
||||
}
|
||||
return repeatedAccumulator.ToString();
|
||||
return repeatedAccumulator.ToString() ?? string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class Day03 : IDay
|
||||
{
|
||||
List<Claim> claims = inputs.Select(Claim.FromString).ToList();
|
||||
|
||||
Claim unOverlappingClaim = null;
|
||||
Claim? unOverlappingClaim = null;
|
||||
for (int i = 0; i < claims.Count; i++)
|
||||
{
|
||||
bool overlaps = false;
|
||||
@@ -113,7 +113,7 @@ public class Day03 : IDay
|
||||
break;
|
||||
}
|
||||
}
|
||||
return unOverlappingClaim.ID.ToString();
|
||||
return unOverlappingClaim?.ID.ToString() ?? string.Empty;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class Day04 : IDay
|
||||
Dictionary<int, GuardSleepHistogram> dictFullHistogram = BuildFullHistogram(guardEvents);
|
||||
|
||||
// Find sleepier guard
|
||||
GuardSleepHistogram highestSleeperHistogram = null;
|
||||
GuardSleepHistogram? highestSleeperHistogram = null;
|
||||
long highestTotalSleep = long.MinValue;
|
||||
foreach (GuardSleepHistogram guardHistogram in dictFullHistogram.Values)
|
||||
{
|
||||
@@ -83,6 +83,7 @@ public class Day04 : IDay
|
||||
highestTotalSleep = totalSleep;
|
||||
}
|
||||
}
|
||||
if (highestSleeperHistogram == null) { return string.Empty; }
|
||||
|
||||
// Find sleepier minute
|
||||
int maxSleepMinute = int.MinValue;
|
||||
|
||||
@@ -97,6 +97,7 @@ public class Day06 : IDay
|
||||
return inputs
|
||||
.Where(input => string.IsNullOrEmpty(input) == false)
|
||||
.Select(ChronoPoint.FromString)
|
||||
.OfType<ChronoPoint>()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -197,7 +198,7 @@ public class Day06 : IDay
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
|
||||
public static ChronoPoint FromString(string strPoint)
|
||||
public static ChronoPoint? FromString(string strPoint)
|
||||
{
|
||||
if (string.IsNullOrEmpty(strPoint)) { return null; }
|
||||
string[] parts = strPoint.Split([", "], StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
@@ -204,7 +204,7 @@ public class Day07 : IDay
|
||||
|
||||
private class SimulatedWorker
|
||||
{
|
||||
public InstructionNode CurrentInstruction { get; private set; }
|
||||
public InstructionNode? CurrentInstruction { get; private set; }
|
||||
private int ElapsedTime { get; set; }
|
||||
|
||||
public void SetInstruction(InstructionNode instruction)
|
||||
|
||||
@@ -87,16 +87,16 @@ public class Day09 : IDay
|
||||
public class Marble
|
||||
{
|
||||
public long Value { get; init; }
|
||||
public Marble Previous { get; set; }
|
||||
public Marble Next { get; set; }
|
||||
public Marble? Previous { get; set; }
|
||||
public Marble? Next { get; set; }
|
||||
}
|
||||
|
||||
public class MarbleGame
|
||||
{
|
||||
private Dictionary<long, long> Scores { get; } = new();
|
||||
|
||||
private Marble _firstMarble;
|
||||
private Marble _currentMarble;
|
||||
private Marble? _firstMarble;
|
||||
private Marble? _currentMarble;
|
||||
private long _currentPlayer;
|
||||
|
||||
private const long PointValueMultiple = 23;
|
||||
@@ -119,8 +119,8 @@ public class Day09 : IDay
|
||||
Marble newMarble = new() { Value = i + 1 };
|
||||
if ((newMarble.Value % PointValueMultiple) > 0)
|
||||
{
|
||||
Marble previousMarble = _currentMarble.Next;
|
||||
Marble nextMarble = previousMarble.Next;
|
||||
Marble? previousMarble = _currentMarble?.Next;
|
||||
Marble? nextMarble = previousMarble?.Next;
|
||||
newMarble.Previous = previousMarble;
|
||||
newMarble.Next = nextMarble;
|
||||
previousMarble.Next = newMarble;
|
||||
@@ -129,7 +129,7 @@ public class Day09 : IDay
|
||||
}
|
||||
else
|
||||
{
|
||||
Marble marbleToRemove = _currentMarble.Previous.Previous.Previous.Previous.Previous.Previous.Previous;
|
||||
Marble? marbleToRemove = _currentMarble?.Previous?.Previous?.Previous?.Previous?.Previous?.Previous?.Previous;
|
||||
_currentMarble = marbleToRemove.Next;
|
||||
marbleToRemove.Previous.Next = marbleToRemove.Next;
|
||||
marbleToRemove.Next.Previous = marbleToRemove.Previous;
|
||||
|
||||
@@ -111,8 +111,8 @@ public class Day12 : IDay
|
||||
private readonly List<bool> _initialState = [];
|
||||
private readonly List<PlantRule> _rules = [];
|
||||
private long _offsetField;
|
||||
private bool[] _field;
|
||||
private bool[] _workField;
|
||||
private bool[]? _field;
|
||||
private bool[]? _workField;
|
||||
|
||||
private void Initialize(string[] inputs)
|
||||
{
|
||||
|
||||
@@ -371,7 +371,7 @@ public class Day13 : IDay
|
||||
|
||||
private int _width;
|
||||
private int _height;
|
||||
private char[,] _grid;
|
||||
private char[,]? _grid;
|
||||
private readonly List<Train> _trains = [];
|
||||
|
||||
private void Initialize(string[] inputs)
|
||||
@@ -430,9 +430,9 @@ public class Day13 : IDay
|
||||
}
|
||||
}
|
||||
|
||||
private Train SimulateForFirstCollision()
|
||||
private Train? SimulateForFirstCollision()
|
||||
{
|
||||
Train collidingTrain = null;
|
||||
Train? collidingTrain = null;
|
||||
IEnumerable<Train> orderedTrains = _trains.OrderBy(t => t.X + (t.Y * _width));
|
||||
foreach (Train t in orderedTrains)
|
||||
{
|
||||
@@ -443,13 +443,13 @@ public class Day13 : IDay
|
||||
return collidingTrain;
|
||||
}
|
||||
|
||||
private Train SimulateForLastCart()
|
||||
private Train? SimulateForLastCart()
|
||||
{
|
||||
List<Train> orderedTrains = _trains.OrderBy(t => t.X + (t.Y * _width)).ToList();
|
||||
foreach (Train t in orderedTrains)
|
||||
{
|
||||
t.Simulate(_grid);
|
||||
Train collidingTrain = _trains.FirstOrDefault(x => x.X == t.X && x.Y == t.Y && t != x);
|
||||
Train? collidingTrain = _trains.FirstOrDefault(x => x.X == t.X && x.Y == t.Y && t != x);
|
||||
if (collidingTrain != null)
|
||||
{
|
||||
_trains.Remove(t);
|
||||
@@ -470,7 +470,7 @@ public class Day13 : IDay
|
||||
{
|
||||
for (int i = 0; i < _width; i++)
|
||||
{
|
||||
Train t = _trains.FirstOrDefault(x => x.X == i && x.Y == j);
|
||||
Train? t = _trains.FirstOrDefault(x => x.X == i && x.Y == j);
|
||||
if (t != null)
|
||||
{
|
||||
if (t.Direction == TrainDirection.North)
|
||||
|
||||
@@ -509,7 +509,7 @@ public class Day15 : IDay
|
||||
.ThenBy(e => e.X);
|
||||
}
|
||||
|
||||
private Entity GetBestInRangeTarget(Entity entity, IEnumerable<Entity> targets)
|
||||
private Entity? GetBestInRangeTarget(Entity entity, IEnumerable<Entity> targets)
|
||||
{
|
||||
return targets
|
||||
.Where(entity.InRangeOf)
|
||||
|
||||
@@ -87,8 +87,8 @@ public class Day16 : IDay
|
||||
int count = 0;
|
||||
int i = 0;
|
||||
bool end = false;
|
||||
int[] beforeRegisters = null;
|
||||
int[] instruction = null;
|
||||
int[]? beforeRegisters = null;
|
||||
int[]? instruction = null;
|
||||
const string beforeKeyword = "Before: [";
|
||||
const string afterKeyword = "After: [";
|
||||
while (inputs.Length > i)
|
||||
|
||||
@@ -68,8 +68,8 @@ public class Day23 : IDay
|
||||
public string ResolvePart1(string[] inputs)
|
||||
{
|
||||
List<NanoBot> nanoBots = NanoBot.ListFromStrings(inputs);
|
||||
NanoBot bestNanoBot = nanoBots.OrderBy(nanoBot => nanoBot.Range).LastOrDefault();
|
||||
int countInRange = nanoBots.Count(nanoBot => bestNanoBot.InRange(nanoBot));
|
||||
NanoBot? bestNanoBot = nanoBots.OrderBy(nanoBot => nanoBot.Range).LastOrDefault();
|
||||
int countInRange = nanoBots.Count(nanoBot => bestNanoBot?.InRange(nanoBot) == true);
|
||||
return countInRange.ToString();
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public class Day23 : IDay
|
||||
public long Z { get; private init; }
|
||||
public long Range { get; private init; }
|
||||
|
||||
private static NanoBot FromString(string strInput)
|
||||
private static NanoBot? FromString(string strInput)
|
||||
{
|
||||
string[] parts = strInput.Split(["pos=<", ",", ">, r="], StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length != 4) { return null; }
|
||||
@@ -167,7 +167,7 @@ public class Day23 : IDay
|
||||
{
|
||||
List<NanoBot> nanoBots = inputs
|
||||
.Select(FromString)
|
||||
.Where(nanoBot => nanoBot != null)
|
||||
.OfType<NanoBot>()
|
||||
.ToList();
|
||||
return nanoBots;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2020.Tests</RootNamespace>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2020</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class Day05 : IDay
|
||||
int maxSerialNumber = 0;
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
Seat seat = Seat_Parse(input);
|
||||
Seat? seat = Seat_Parse(input);
|
||||
if (seat == null) { continue; }
|
||||
int newSerialNumber = seat.GetSerialNumber();
|
||||
if (newSerialNumber > maxSerialNumber) { maxSerialNumber = newSerialNumber; }
|
||||
@@ -83,7 +83,7 @@ public class Day05 : IDay
|
||||
}
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
Seat seat = Seat_Parse(input);
|
||||
Seat? seat = Seat_Parse(input);
|
||||
if (seat == null) { continue; }
|
||||
|
||||
seats[seat.Column][seat.Row] = 'X';
|
||||
@@ -166,7 +166,7 @@ public class Day05 : IDay
|
||||
}
|
||||
}
|
||||
|
||||
private Seat Seat_Parse(string input)
|
||||
private Seat? Seat_Parse(string input)
|
||||
{
|
||||
if (input.Length != 10 ||
|
||||
input.All(c => c == 'F' || c == 'B' || c == 'L' || c == 'R') == false
|
||||
|
||||
@@ -141,7 +141,7 @@ public class Day07 : IDay
|
||||
BaggageRule rule = new() {
|
||||
Contain = [],
|
||||
};
|
||||
BaggageContainRule containRule = null;
|
||||
BaggageContainRule? containRule = null;
|
||||
string color1 = string.Empty;
|
||||
|
||||
foreach (string word in words)
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>AdventOfCode2023.Tests</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2023.Tests</RootNamespace>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>AdventOfCode2023</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2023</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>AdventOfCode2024.Tests</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2024.Tests</RootNamespace>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
@@ -17,10 +17,6 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>AdventOfCode2024</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>AdventOfCode2024</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user