public override void Part1() { int lookupWindowSize = 25; FixedListWrapper <int> lookupWindow = new FixedListWrapper <int>(lookupWindowSize); for (int lookupIndex = 0; lookupIndex < lookupWindowSize; lookupIndex++) { var val = Int32.Parse(Input[lookupIndex]); lookupWindow.Add(val); } for (int checkIndex = lookupWindowSize; checkIndex < Input.Length; checkIndex++) { var nextVal = Int32.Parse(Input[checkIndex]); if (!ValueIsValid(nextVal, lookupWindow)) { Console.WriteLine($"Found bad value: {nextVal}"); InvalidNumber = nextVal; return; } lookupWindow.Add(nextVal); } Console.WriteLine("No bad value found"); }
private bool ValueIsValid(int checkedValue, FixedListWrapper <int> lookupWindow) { for (int first = 0; first < lookupWindow.Count - 1; first++) { for (int second = first + 1; second < lookupWindow.Count; second++) { if (lookupWindow[first] + lookupWindow[second] == checkedValue) { return(true); } } } return(false); }