fix nullable logic
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f6b72dd9ee
commit
ffb4a8e7a4
|
@ -29,7 +29,7 @@ public sealed class Day03 : Day
|
||||||
|
|
||||||
foreach (var step in line.Split(','))
|
foreach (var step in line.Split(','))
|
||||||
{
|
{
|
||||||
var d = int.Parse(step.Substring(1));
|
var d = int.Parse(step[1..]);
|
||||||
switch (step[0])
|
switch (step[0])
|
||||||
{
|
{
|
||||||
case 'U':
|
case 'U':
|
||||||
|
|
|
@ -17,7 +17,7 @@ public sealed class Day15 : Day
|
||||||
var halt = IntCodeVM.HaltType.Waiting;
|
var halt = IntCodeVM.HaltType.Waiting;
|
||||||
while (halt == IntCodeVM.HaltType.Waiting)
|
while (halt == IntCodeVM.HaltType.Waiting)
|
||||||
{
|
{
|
||||||
var direction = currentLocation.NextDirection();
|
var direction = currentLocation!.NextDirection();
|
||||||
if (direction <= 4)
|
if (direction <= 4)
|
||||||
{
|
{
|
||||||
var (x, y) = currentLocation.Neighbor(direction);
|
var (x, y) = currentLocation.Neighbor(direction);
|
||||||
|
@ -46,15 +46,11 @@ public sealed class Day15 : Day
|
||||||
if (direction > 0)
|
if (direction > 0)
|
||||||
{
|
{
|
||||||
halt = vm.Run(direction);
|
halt = vm.Run(direction);
|
||||||
switch (vm.Result)
|
currentLocation = vm.Result switch
|
||||||
{
|
{
|
||||||
case Location.Empty:
|
Location.Empty or Location.System => Location.GetLocation(currentLocation.Neighbor(direction)),
|
||||||
case Location.System:
|
_ => throw new Exception($"Unknown or unexpected response for previous room: {vm.Result}"),
|
||||||
currentLocation = Location.GetLocation(currentLocation.Neighbor(direction));
|
};
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Exception($"Unknown or unexpected response for previous room: {vm.Result}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -90,10 +86,10 @@ public sealed class Day15 : Day
|
||||||
|
|
||||||
currentLocation = Location.OxygenLocation;
|
currentLocation = Location.OxygenLocation;
|
||||||
var distance = 0;
|
var distance = 0;
|
||||||
while (currentLocation.PreviousDirection != 0)
|
while (currentLocation?.PreviousDirection != 0)
|
||||||
{
|
{
|
||||||
distance++;
|
distance++;
|
||||||
currentLocation = Location.GetLocation(currentLocation.PreviousLocation());
|
currentLocation = Location.GetLocation(currentLocation!.PreviousLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $"{distance}";
|
return $"{distance}";
|
||||||
|
@ -154,7 +150,7 @@ public sealed class Day15 : Day
|
||||||
AllLocations.Add((x, y), this);
|
AllLocations.Add((x, y), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location OxygenLocation { get; private set; }
|
public static Location? OxygenLocation { get; private set; }
|
||||||
public int PreviousDirection { get; }
|
public int PreviousDirection { get; }
|
||||||
private int X { get; }
|
private int X { get; }
|
||||||
private int Y { get; }
|
private int Y { get; }
|
||||||
|
@ -204,12 +200,12 @@ public sealed class Day15 : Day
|
||||||
return searchDirection++;
|
return searchDirection++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location GetLocation(int x, int y)
|
public static Location? GetLocation(int x, int y)
|
||||||
{
|
{
|
||||||
return AllLocations.ContainsKey((x, y)) ? AllLocations[(x, y)] : null;
|
return AllLocations.ContainsKey((x, y)) ? AllLocations[(x, y)] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location GetLocation((int x, int y) coords)
|
public static Location? GetLocation((int x, int y) coords)
|
||||||
{
|
{
|
||||||
return GetLocation(coords.x, coords.y);
|
return GetLocation(coords.x, coords.y);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue