about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2021-12-07 14:51:30 -0500
committerBen Harris <ben@tilde.team>2021-12-07 14:51:30 -0500
commit9f1a502a61141e8d3d2aa81332904cd9194604c4 (patch)
treec48886d92429bd160d37ae997287c35e18a6ac94
parentc0a75342201f18fd813ce63fe88aed26b35e4ada (diff)
switch day 7 to use longs
-rw-r--r--aoc2021/Day07.cs10
1 files changed, 5 insertions, 5 deletions
diff --git a/aoc2021/Day07.cs b/aoc2021/Day07.cs
index b5db0ee..0b936f3 100644
--- a/aoc2021/Day07.cs
+++ b/aoc2021/Day07.cs
@@ -5,14 +5,14 @@
 /// </summary>
 public sealed class Day07 : Day
 {
-    private readonly List<int> _tape;
+    private readonly List<long> _tape;
     
     public Day07() : base(7, "The Treachery of Whales")
     {
-        _tape = Input.First().Split(',').Select(int.Parse).OrderBy(i => i).ToList();
+        _tape = Input.First().Split(',').Select(long.Parse).OrderBy(i => i).ToList();
     }
 
-    private static int ArithmeticSumTo(int n) => n * (n + 1) / 2;
+    private static long ArithmeticSumTo(long n) => n * (n + 1) / 2L;
 
     public override string Part1()
     {
@@ -23,8 +23,8 @@ public sealed class Day07 : Day
     public override string Part2()
     {
         var avg = (decimal)_tape.Sum() / _tape.Count;
-        var floor = _tape.Select(t => ArithmeticSumTo(Math.Abs(t - (int)Math.Floor(avg)))).Sum();
-        var ceil = _tape.Select(t => ArithmeticSumTo(Math.Abs(t - (int)Math.Ceiling(avg)))).Sum();
+        var floor = _tape.Select(t => ArithmeticSumTo(Math.Abs(t - (long)Math.Floor(avg)))).Sum();
+        var ceil  = _tape.Select(t => ArithmeticSumTo(Math.Abs(t - (long)Math.Ceiling(avg)))).Sum();
         return $"{Math.Min(floor, ceil)}";
     }
 }