From 0cad16b5a452b659206b223a4cf2ba0dd517e9c3 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 9 Dec 2020 08:42:04 -0500 Subject: [PATCH] ints -> longs --- 2020/Day09.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/2020/Day09.cs b/2020/Day09.cs index 039f0c2..1519f39 100644 --- a/2020/Day09.cs +++ b/2020/Day09.cs @@ -10,13 +10,13 @@ namespace AdventOfCode { public class Day09 { - static bool Valid(List ints, int preambleSize, int target) { + static bool Valid(List longs, int preambleSize, int target) { for (int i = target - preambleSize; i < target - 1; i++) { for (int j = i + 1; j < target; j++) { if (i == j) { continue; } - if (ints[i] + ints[j] == ints[target]) { + if (longs[i] + longs[j] == longs[target]) { return true; } } @@ -24,10 +24,10 @@ namespace AdventOfCode { return false; } - static long FindInvalid(List ints, int preambleSize) { - for (int target = preambleSize; target < ints.Count(); target++) { - if (!Valid(ints, preambleSize, target)) { - return ints[target]; + static long FindInvalid(List longs, int preambleSize) { + for (int target = preambleSize; target < longs.Count(); target++) { + if (!Valid(longs, preambleSize, target)) { + return longs[target]; } } throw new Exception("didn't find an invalid int"); @@ -35,8 +35,8 @@ namespace AdventOfCode { static long Part1() { string[] input = File.ReadAllLines(Util.RootDir + "day09.txt"); - List ints = input.ToList().Select(long.Parse).ToList(); - return FindInvalid(ints, 25); + List longs = input.ToList().Select(long.Parse).ToList(); + return FindInvalid(longs, 25); } static int Part2() { @@ -66,8 +66,8 @@ namespace AdventOfCode { 277 309 576".Split('\n'); - List ints = example.ToList().Select(long.Parse).ToList(); - Assert.Equal(127, FindInvalid(ints, 5)); + List longs = example.ToList().Select(long.Parse).ToList(); + Assert.Equal(127, FindInvalid(longs, 5)); Assert.Equal(50047984, Part1()); Assert.Equal(-1, Part2());