diff --git a/Day2/Program.cs b/Day2/Program.cs index 9bdb711..9ec7045 100644 --- a/Day2/Program.cs +++ b/Day2/Program.cs @@ -29,7 +29,6 @@ Console.WriteLine(levelsSafe); bool TestLevel(LinkedList linkedList) { - int unsafeCount = 0; var node = linkedList.First; List directions = new List(); while (node != null) @@ -47,7 +46,7 @@ bool TestLevel(LinkedList linkedList) if(safeRange is false) { - unsafeCount++; + return false; } if (node.Next is not null) @@ -61,8 +60,7 @@ bool TestLevel(LinkedList linkedList) bool allIncreasing = directions.All(x => x == LevelDirection.Increasing); bool allDecreasing = directions.All(x => x == LevelDirection.Decreasing); - Console.Write($" {unsafeCount}|{allIncreasing}|{allDecreasing} "); - return ((allIncreasing || allDecreasing) && unsafeCount == 0) || (allIncreasing == false && allDecreasing == false); + return allIncreasing || allDecreasing; bool InsideRange(int current, int target) { diff --git a/Day3/Program.cs b/Day3/Program.cs index 00de21f..3737a83 100644 --- a/Day3/Program.cs +++ b/Day3/Program.cs @@ -3,10 +3,11 @@ string input = File.ReadAllText("input.txt").ReplaceLineEndings(""); int total = 0; -Regex valid = new Regex("mul\\((?[0-9]+),(?[0-9]+)\\)"); -Regex dontandDo = new Regex("(don\\'t\\(\\).*?do\\(\\))"); +Regex valid = new Regex(@"mul\((?[0-9]+),(?[0-9]+)\)"); +Regex dontandDo = new Regex(@"(don\'t\(\).*?do\(\))"); input = dontandDo.Replace(input, ""); +int muls = valid.Count(input); List<(int x, int y)> multiplies = new(); @@ -22,4 +23,4 @@ foreach ((int x, int y) in multiplies) total += x * y; } -Console.WriteLine(total); \ No newline at end of file +Console.WriteLine($"muls: {muls}"); \ No newline at end of file