Enable nullability
I thought this was the old way. Apparently it's the new way.
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<RootNamespace>aoc2021</RootNamespace>
|
<RootNamespace>aoc2021</RootNamespace>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>disable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
|
||||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -15,7 +15,7 @@ namespace aoc2021
|
|||||||
|
|
||||||
public bool Equals(Point other) => X == other.X && Y == other.Y;
|
public bool Equals(Point other) => X == other.X && Y == other.Y;
|
||||||
|
|
||||||
public override bool Equals(object obj) => obj is Point point && Equals(point);
|
public override bool Equals(object? obj) => obj is Point point && Equals(point);
|
||||||
|
|
||||||
public override int GetHashCode() => HashCode.Combine(X, Y);
|
public override int GetHashCode() => HashCode.Combine(X, Y);
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
{
|
{
|
||||||
var min = nums.Min();
|
var min = nums.Min();
|
||||||
var max = nums.Max();
|
var max = nums.Max();
|
||||||
long minDist = 0;
|
long minDist = long.MaxValue;
|
||||||
int? minNum = null;
|
int minNum = 0;
|
||||||
for (int i = min; i <= max; i++)
|
for (int i = min; i <= max; i++)
|
||||||
{
|
{
|
||||||
long dist = 0;
|
long dist = 0;
|
||||||
@ -26,14 +26,14 @@
|
|||||||
dist += formula(Math.Abs(num - i));
|
dist += formula(Math.Abs(num - i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minNum == null || dist < minDist)
|
if (dist < minDist)
|
||||||
{
|
{
|
||||||
minDist = dist;
|
minDist = dist;
|
||||||
minNum = i;
|
minNum = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (minDist, minNum.Value);
|
return (minDist, minNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Part1(IEnumerable<int> nums)
|
private static void Part1(IEnumerable<int> nums)
|
||||||
|
Reference in New Issue
Block a user