fix: Fixed Day 2 - part 2 not working yet
This commit is contained in:
@@ -29,7 +29,6 @@ Console.WriteLine(levelsSafe);
|
||||
|
||||
bool TestLevel(LinkedList<int> linkedList)
|
||||
{
|
||||
int unsafeCount = 0;
|
||||
var node = linkedList.First;
|
||||
List<LevelDirection> directions = new List<LevelDirection>();
|
||||
while (node != null)
|
||||
@@ -47,7 +46,7 @@ bool TestLevel(LinkedList<int> linkedList)
|
||||
|
||||
if(safeRange is false)
|
||||
{
|
||||
unsafeCount++;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (node.Next is not null)
|
||||
@@ -61,8 +60,7 @@ bool TestLevel(LinkedList<int> 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)
|
||||
{
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
string input = File.ReadAllText("input.txt").ReplaceLineEndings("");
|
||||
int total = 0;
|
||||
|
||||
Regex valid = new Regex("mul\\((?<x>[0-9]+),(?<y>[0-9]+)\\)");
|
||||
Regex dontandDo = new Regex("(don\\'t\\(\\).*?do\\(\\))");
|
||||
Regex valid = new Regex(@"mul\((?<x>[0-9]+),(?<y>[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);
|
||||
Console.WriteLine($"muls: {muls}");
|
||||
Reference in New Issue
Block a user