Browse Source

Add day 3 part i solution

As usual, I was forgetting to put the last thing found in a double
for-loop into the array.
ApisNecros 1 year ago
parent
commit
9e783fd58a
1 changed files with 23 additions and 1 deletions
  1. 23 1
      3/3_1.ts

+ 23 - 1
3/3_1.ts

@@ -49,6 +49,25 @@ const tests = [
     ".664.598..",
 ];
 
+/**
+ * Test case from /u/i_have_no_biscuits
+ * @see https://www.reddit.com/r/adventofcode/comments/189q9wv/2023_day_3_another_sample_grid_to_use/
+ */
+const tests_reddit = [
+    "12.......*..",
+    "+.........34",
+    ".......-12..",
+    "..78........",
+    "..*....60...",
+    "78..........",
+    ".......23...",
+    "....90*12...",
+    "............",
+    "2.2......12.",
+    ".*.........*",
+    "1.1.......56",
+];
+
 const input = await LoadInput(3);
 
 // Build the find
@@ -59,7 +78,6 @@ let engineParts = ParseSchematics(schematics);
 engineParts = ValidateEngineParts(engineParts, schematics);
 
 // Get our output
-// 551521: too low
 const sumOfPartNumbers = engineParts.reduce((accumulator, part) => accumulator += part.PartNumber, 0);
 console.log(`The sum of part numbers is: ${sumOfPartNumbers}`);
 
@@ -119,6 +137,10 @@ function ParseSchematics(schematicsMap: string[][]): EnginePart[] {
                 }
             }
         }
+
+        if(part !== null) {
+            engineParts.push(part);
+        }
     }
 
     return engineParts;