fix: Fixed Day 2 - part 2 not working yet

This commit is contained in:
henrik
2024-12-03 22:25:41 +01:00
parent fb3a16c772
commit e08b82342b
2 changed files with 6 additions and 7 deletions

View File

@@ -29,7 +29,6 @@ Console.WriteLine(levelsSafe);
bool TestLevel(LinkedList<int> linkedList) bool TestLevel(LinkedList<int> linkedList)
{ {
int unsafeCount = 0;
var node = linkedList.First; var node = linkedList.First;
List<LevelDirection> directions = new List<LevelDirection>(); List<LevelDirection> directions = new List<LevelDirection>();
while (node != null) while (node != null)
@@ -47,7 +46,7 @@ bool TestLevel(LinkedList<int> linkedList)
if(safeRange is false) if(safeRange is false)
{ {
unsafeCount++; return false;
} }
if (node.Next is not null) if (node.Next is not null)
@@ -61,8 +60,7 @@ bool TestLevel(LinkedList<int> linkedList)
bool allIncreasing = directions.All(x => x == LevelDirection.Increasing); bool allIncreasing = directions.All(x => x == LevelDirection.Increasing);
bool allDecreasing = directions.All(x => x == LevelDirection.Decreasing); bool allDecreasing = directions.All(x => x == LevelDirection.Decreasing);
Console.Write($" {unsafeCount}|{allIncreasing}|{allDecreasing} "); return allIncreasing || allDecreasing;
return ((allIncreasing || allDecreasing) && unsafeCount == 0) || (allIncreasing == false && allDecreasing == false);
bool InsideRange(int current, int target) bool InsideRange(int current, int target)
{ {

View File

@@ -3,10 +3,11 @@
string input = File.ReadAllText("input.txt").ReplaceLineEndings(""); string input = File.ReadAllText("input.txt").ReplaceLineEndings("");
int total = 0; int total = 0;
Regex valid = new Regex("mul\\((?<x>[0-9]+),(?<y>[0-9]+)\\)"); Regex valid = new Regex(@"mul\((?<x>[0-9]+),(?<y>[0-9]+)\)");
Regex dontandDo = new Regex("(don\\'t\\(\\).*?do\\(\\))"); Regex dontandDo = new Regex(@"(don\'t\(\).*?do\(\))");
input = dontandDo.Replace(input, ""); input = dontandDo.Replace(input, "");
int muls = valid.Count(input);
List<(int x, int y)> multiplies = new(); List<(int x, int y)> multiplies = new();
@@ -22,4 +23,4 @@ foreach ((int x, int y) in multiplies)
total += x * y; total += x * y;
} }
Console.WriteLine(total); Console.WriteLine($"muls: {muls}");