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>
|
||||
|
||||
@@ -7,28 +7,28 @@ public class Day06_Tests
|
||||
[Fact]
|
||||
public void ChronoPoint_FromString__Test1()
|
||||
{
|
||||
Day06.ChronoPoint point = Day06.ChronoPoint.FromString("1, 1");
|
||||
Day06.ChronoPoint? point = Day06.ChronoPoint.FromString("1, 1");
|
||||
|
||||
Assert.Equal(1, point.X);
|
||||
Assert.Equal(1, point.Y);
|
||||
Assert.Equal(1, point?.X);
|
||||
Assert.Equal(1, point?.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChronoPoint_FromString__Test2()
|
||||
{
|
||||
Day06.ChronoPoint point = Day06.ChronoPoint.FromString("1, 6");
|
||||
Day06.ChronoPoint? point = Day06.ChronoPoint.FromString("1, 6");
|
||||
|
||||
Assert.Equal(1, point.X);
|
||||
Assert.Equal(6, point.Y);
|
||||
Assert.Equal(1, point?.X);
|
||||
Assert.Equal(6, point?.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ChronoPoint_FromString__Test3()
|
||||
{
|
||||
Day06.ChronoPoint point = Day06.ChronoPoint.FromString("8, 9");
|
||||
Day06.ChronoPoint? point = Day06.ChronoPoint.FromString("8, 9");
|
||||
|
||||
Assert.Equal(8, point.X);
|
||||
Assert.Equal(9, point.Y);
|
||||
Assert.Equal(8, point?.X);
|
||||
Assert.Equal(9, point?.Y);
|
||||
}
|
||||
|
||||
#endregion ChronoPoint_FromString
|
||||
@@ -38,8 +38,11 @@ public class Day06_Tests
|
||||
[Fact]
|
||||
public void ChronoPoint_ManhattanDistance__Test1()
|
||||
{
|
||||
Day06.ChronoPoint p0 = Day06.ChronoPoint.FromString("8, 9");
|
||||
Day06.ChronoPoint p1 = Day06.ChronoPoint.FromString("1, 6");
|
||||
Day06.ChronoPoint? p0 = Day06.ChronoPoint.FromString("8, 9");
|
||||
Day06.ChronoPoint? p1 = Day06.ChronoPoint.FromString("1, 6");
|
||||
|
||||
Assert.NotNull(p0);
|
||||
Assert.NotNull(p1);
|
||||
|
||||
int distance = Day06.ChronoPoint.ManhattanDistance(p0, p1);
|
||||
|
||||
@@ -49,8 +52,11 @@ public class Day06_Tests
|
||||
[Fact]
|
||||
public void ChronoPoint_ManhattanDistance__Test2()
|
||||
{
|
||||
Day06.ChronoPoint p0 = Day06.ChronoPoint.FromString("1, 1");
|
||||
Day06.ChronoPoint p1 = Day06.ChronoPoint.FromString("1, 6");
|
||||
Day06.ChronoPoint? p0 = Day06.ChronoPoint.FromString("1, 1");
|
||||
Day06.ChronoPoint? p1 = Day06.ChronoPoint.FromString("1, 6");
|
||||
|
||||
Assert.NotNull(p0);
|
||||
Assert.NotNull(p1);
|
||||
|
||||
int distance = Day06.ChronoPoint.ManhattanDistance(p0, p1);
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -156,14 +157,12 @@ public class Day04 : IDay
|
||||
|
||||
foreach (GuardSleepHistogram dayGuardHistogram in dictDayHistogram.Values)
|
||||
{
|
||||
if (dictFullHistogram.TryGetValue(dayGuardHistogram.ID, out GuardSleepHistogram guardHistogram))
|
||||
if (dictFullHistogram.TryGetValue(dayGuardHistogram.ID, out GuardSleepHistogram? guardHistogram))
|
||||
{
|
||||
guardHistogram.AddHistogram(dayGuardHistogram);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
dictFullHistogram.Add(dayGuardHistogram.ID, dayGuardHistogram);
|
||||
}
|
||||
dictFullHistogram.Add(dayGuardHistogram.ID, dayGuardHistogram);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -128,9 +128,9 @@ public class Day07 : IDay
|
||||
return totalElapsedTime.ToString();
|
||||
}
|
||||
|
||||
public class InstructionNode
|
||||
public class InstructionNode(string nodeID)
|
||||
{
|
||||
public string NodeID { get; init; }
|
||||
public string NodeID { get; init; } = nodeID;
|
||||
|
||||
public List<string> PreviousNodeIDs { get; } = [];
|
||||
|
||||
@@ -154,16 +154,12 @@ public class Day07 : IDay
|
||||
|
||||
private InstructionNode GetNode(string nodeID)
|
||||
{
|
||||
InstructionNode node;
|
||||
if (Nodes.TryGetValue(nodeID, out InstructionNode nodeAux))
|
||||
if (Nodes.TryGetValue(nodeID, out InstructionNode? nodeAux))
|
||||
{
|
||||
node = nodeAux;
|
||||
}
|
||||
else
|
||||
{
|
||||
node = new InstructionNode { NodeID = nodeID, };
|
||||
Nodes.Add(nodeID, node);
|
||||
return nodeAux;
|
||||
}
|
||||
InstructionNode node = new(nodeID);
|
||||
Nodes.Add(nodeID, node);
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -194,7 +190,8 @@ public class Day07 : IDay
|
||||
.ToList();
|
||||
if (unusedNodes.Count > 0)
|
||||
{
|
||||
InstructionNode node = unusedNodes.FirstOrDefault();
|
||||
InstructionNode? node = unusedNodes.FirstOrDefault();
|
||||
if (node == null) { continue; }
|
||||
finalNodes.Add(node);
|
||||
node.Used = true;
|
||||
}
|
||||
@@ -204,7 +201,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,20 +119,34 @@ 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;
|
||||
nextMarble.Previous = newMarble;
|
||||
if(previousMarble != null)
|
||||
{
|
||||
previousMarble.Next = newMarble;
|
||||
}
|
||||
if(nextMarble != null)
|
||||
{
|
||||
nextMarble.Previous = newMarble;
|
||||
}
|
||||
_currentMarble = newMarble;
|
||||
}
|
||||
else
|
||||
{
|
||||
Marble marbleToRemove = _currentMarble.Previous.Previous.Previous.Previous.Previous.Previous.Previous;
|
||||
_currentMarble = marbleToRemove.Next;
|
||||
marbleToRemove.Previous.Next = marbleToRemove.Next;
|
||||
marbleToRemove.Next.Previous = marbleToRemove.Previous;
|
||||
Marble? marbleToRemove = _currentMarble?.Previous?.Previous?.Previous?.Previous?.Previous?.Previous?.Previous;
|
||||
_currentMarble = marbleToRemove?.Next;
|
||||
if (marbleToRemove == null) { continue; }
|
||||
|
||||
if(marbleToRemove.Previous != null)
|
||||
{
|
||||
marbleToRemove.Previous.Next = marbleToRemove.Next;
|
||||
}
|
||||
if (marbleToRemove.Next != null)
|
||||
{
|
||||
marbleToRemove.Next.Previous = marbleToRemove.Previous;
|
||||
}
|
||||
|
||||
long currentPlayerScore = Scores[_currentPlayer] + (newMarble.Value + marbleToRemove.Value);
|
||||
Scores[_currentPlayer] = currentPlayerScore;
|
||||
@@ -144,14 +158,14 @@ public class Day09 : IDay
|
||||
private void PrintStatus()
|
||||
{
|
||||
Console.Write("[{0}] ", _currentPlayer);
|
||||
Marble marble = _firstMarble;
|
||||
Marble? marble = _firstMarble;
|
||||
do
|
||||
{
|
||||
Console.Write(_currentMarble.Value == marble.Value
|
||||
Console.Write(_currentMarble?.Value == marble?.Value
|
||||
? "({0}) "
|
||||
: "{0} ", marble.Value);
|
||||
marble = marble.Next;
|
||||
} while (marble.Value != 0);
|
||||
: "{0} ", marble?.Value);
|
||||
marble = marble?.Next;
|
||||
} while (marble != null && marble.Value != 0);
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -217,7 +217,7 @@ public class Day13 : IDay
|
||||
public string ResolvePart1(string[] inputs)
|
||||
{
|
||||
Initialize(inputs);
|
||||
Train collidingTrain;
|
||||
Train? collidingTrain;
|
||||
do
|
||||
{
|
||||
if (ShowProgress) { ShowGrid(); }
|
||||
@@ -229,7 +229,7 @@ public class Day13 : IDay
|
||||
public string ResolvePart2(string[] inputs)
|
||||
{
|
||||
Initialize(inputs);
|
||||
Train lastCart;
|
||||
Train? lastCart;
|
||||
do
|
||||
{
|
||||
if (ShowProgress) { ShowGrid(); }
|
||||
@@ -371,7 +371,7 @@ public class Day13 : IDay
|
||||
|
||||
private int _width;
|
||||
private int _height;
|
||||
private char[,] _grid;
|
||||
private char[,] _grid = new char[0, 0];
|
||||
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)
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Day14 : IDay
|
||||
{
|
||||
private long _numRecipes;
|
||||
private long _numRecipesAllocated;
|
||||
private byte[] _recipes;
|
||||
private byte[] _recipes = [];
|
||||
private long _idxA;
|
||||
private long _idxB;
|
||||
private long _searchSkip;
|
||||
|
||||
@@ -444,9 +444,9 @@ public class Day15 : IDay
|
||||
|
||||
private int _width;
|
||||
private int _height;
|
||||
private char[,] _map;
|
||||
private List<Entity> _entities;
|
||||
private BreadthFirstSearchGrid _search;
|
||||
private char[,] _map = new char[0, 0];
|
||||
private readonly List<Entity> _entities = [];
|
||||
private BreadthFirstSearchGrid? _search;
|
||||
private int _rounds;
|
||||
|
||||
private void Init(string[] inputs)
|
||||
@@ -454,7 +454,7 @@ public class Day15 : IDay
|
||||
_height = inputs.Length;
|
||||
_width = inputs.Max(input => input.Length);
|
||||
_map = new char[_width, _height];
|
||||
_entities = new List<Entity>();
|
||||
_entities.Clear();
|
||||
for (int j = 0; j < _height; j++)
|
||||
{
|
||||
for (int i = 0; i < _width; i++)
|
||||
@@ -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)
|
||||
@@ -521,6 +521,7 @@ public class Day15 : IDay
|
||||
|
||||
private void AddTarget(List<Target> targets, int targetX, int targetY, int priority)
|
||||
{
|
||||
if (_search == null) { return;}
|
||||
if (targetX >= 0 && targetX < _width && targetY >= 0 && targetY < _height && _map[targetX, targetY] == '.')
|
||||
{
|
||||
int distance = _search.QueryDistance(targetX, targetY);
|
||||
@@ -538,6 +539,7 @@ public class Day15 : IDay
|
||||
|
||||
private void RunBattle()
|
||||
{
|
||||
if (_search == null) { return;}
|
||||
_rounds = 0;
|
||||
bool running = true;
|
||||
do
|
||||
@@ -554,7 +556,7 @@ public class Day15 : IDay
|
||||
}
|
||||
|
||||
// Attack
|
||||
Entity targetInRange = GetBestInRangeTarget(entity, entitiesTargets);
|
||||
Entity? targetInRange = GetBestInRangeTarget(entity, entitiesTargets);
|
||||
if (targetInRange != null)
|
||||
{
|
||||
entity.Attack(_map, targetInRange);
|
||||
@@ -572,7 +574,7 @@ public class Day15 : IDay
|
||||
AddTarget(targets, entityTarget.X + 1, entityTarget.Y, priority++);
|
||||
AddTarget(targets, entityTarget.X, entityTarget.Y + 1, priority++);
|
||||
}
|
||||
Target bestTarget = targets.OrderBy(t => t.Distance).ThenBy(t => t.Priority).FirstOrDefault();
|
||||
Target? bestTarget = targets.OrderBy(t => t.Distance).ThenBy(t => t.Priority).FirstOrDefault();
|
||||
if (bestTarget != null)
|
||||
{
|
||||
_search.SearchCharGrid(_map, '.', bestTarget.X, bestTarget.Y);
|
||||
@@ -594,7 +596,7 @@ public class Day15 : IDay
|
||||
dirTarget.Distance = _search.QueryDistance(dirTarget.X, dirTarget.Y);
|
||||
if (dirTarget.Distance >= 0) targets.Add(dirTarget);
|
||||
|
||||
Target finalTarget = targets
|
||||
Target? finalTarget = targets
|
||||
.OrderBy(t => t.Distance)
|
||||
.ThenBy(t => t.Priority)
|
||||
.FirstOrDefault();
|
||||
@@ -606,7 +608,7 @@ public class Day15 : IDay
|
||||
entity.MoveTo(_map, finalTarget.X, finalTarget.Y);
|
||||
|
||||
// Attack
|
||||
Entity targetInRangeAfterMove = GetBestInRangeTarget(entity, entitiesTargets);
|
||||
Entity? targetInRangeAfterMove = GetBestInRangeTarget(entity, entitiesTargets);
|
||||
if (targetInRangeAfterMove != null)
|
||||
{
|
||||
entity.Attack(_map, targetInRangeAfterMove);
|
||||
@@ -713,7 +715,7 @@ public class Day15 : IDay
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessCell(char[,] grid, char empty, Queue<BFSCell> frontier, BFSCell current, int nextX, int nextY)
|
||||
private void ProcessCell(char[,] grid, char empty, Queue<BFSCell> frontier, BFSCell? current, int nextX, int nextY)
|
||||
{
|
||||
if (nextX < 0 || nextX >= _width || nextY < 0 || nextY >= _height) { return; }
|
||||
if (grid[nextX, nextY] == empty || current == null)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -123,25 +123,23 @@ public class Day07 : IDay
|
||||
|
||||
private class BaggageContainRule
|
||||
{
|
||||
public string BagColor { get; set; }
|
||||
public string BagColor { get; set; } = string.Empty;
|
||||
public int Count { get; init; }
|
||||
}
|
||||
|
||||
private class BaggageRule
|
||||
{
|
||||
public string BagColor { get; set; }
|
||||
public string BagColor { get; set; } = string.Empty;
|
||||
|
||||
public List<BaggageContainRule> Contain { get; init; }
|
||||
public List<BaggageContainRule> Contain { get; } = [];
|
||||
}
|
||||
|
||||
private BaggageRule BaggageRule_Parse(string input)
|
||||
{
|
||||
string[] words = input.Split(' ');
|
||||
string status = "Parse Color 1";
|
||||
BaggageRule rule = new() {
|
||||
Contain = [],
|
||||
};
|
||||
BaggageContainRule containRule = null;
|
||||
BaggageRule rule = new();
|
||||
BaggageContainRule? containRule = null;
|
||||
string color1 = string.Empty;
|
||||
|
||||
foreach (string word in words)
|
||||
@@ -180,6 +178,7 @@ public class Day07 : IDay
|
||||
status = "Parse Contain color 2";
|
||||
break;
|
||||
case "Parse Contain color 2":
|
||||
if(containRule == null) { break; }
|
||||
containRule.BagColor = string.Concat(color1, " ", word);
|
||||
rule.Contain.Add(containRule);
|
||||
status = "Parse Contain continue";
|
||||
|
||||
@@ -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