Explorar el Código

Add day 3 part 1 solution

ApisNecros hace 2 semanas
padre
commit
a565255ace
Se han modificado 2 ficheros con 25 adiciones y 0 borrados
  1. 24 0
      3/3_1.js
  2. 1 0
      3/test.input

+ 24 - 0
3/3_1.js

@@ -0,0 +1,24 @@
+import { loadInput } from "../common.js";
+
+// const input = loadInput("./3/test.input", parseInput, true);
+const input = loadInput(3, parseInput);
+
+solve(input);
+
+/**
+ * @param {string} memDump
+ */
+function parseInput(memDump) {
+    return Array.from(memDump.matchAll(/(mul\(\d{1,3},\d{1,3}\))/g));
+}
+
+function solve(validInstructions) {
+    let sum = 0;
+    for(const inst of validInstructions) {
+        sum += eval(inst[0]);
+    }
+
+    console.log("Sum of result of valid instructions:", sum);
+}
+
+function mul(a,b) { return a*b; }

+ 1 - 0
3/test.input

@@ -0,0 +1 @@
+xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))