From 0dd261b964afe96615c7cde09f15091265b2faff Mon Sep 17 00:00:00 2001 From: Parnic Date: Wed, 8 Dec 2021 11:55:19 -0600 Subject: [PATCH] Enable nullability I thought this was the old way. Apparently it's the new way. --- advent-of-code-2021.csproj | 2 +- src/05.cs | 2 +- src/07.cs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/advent-of-code-2021.csproj b/advent-of-code-2021.csproj index a675df4..cd2fde3 100644 --- a/advent-of-code-2021.csproj +++ b/advent-of-code-2021.csproj @@ -5,7 +5,7 @@ net6.0 aoc2021 enable - disable + enable False True diff --git a/src/05.cs b/src/05.cs index 96ed5a1..9419957 100644 --- a/src/05.cs +++ b/src/05.cs @@ -15,7 +15,7 @@ namespace aoc2021 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); } diff --git a/src/07.cs b/src/07.cs index 2fee115..9a6c66a 100644 --- a/src/07.cs +++ b/src/07.cs @@ -16,8 +16,8 @@ { var min = nums.Min(); var max = nums.Max(); - long minDist = 0; - int? minNum = null; + long minDist = long.MaxValue; + int minNum = 0; for (int i = min; i <= max; i++) { long dist = 0; @@ -26,14 +26,14 @@ dist += formula(Math.Abs(num - i)); } - if (minNum == null || dist < minDist) + if (dist < minDist) { minDist = dist; minNum = i; } } - return (minDist, minNum.Value); + return (minDist, minNum); } private static void Part1(IEnumerable nums)