3_1.js 533 B

123456789101112131415161718192021222324
  1. import { loadInput } from "../common.js";
  2. // const input = loadInput("./3/test.input", parseInput, true);
  3. const input = loadInput(3, parseInput);
  4. solve(input);
  5. /**
  6. * @param {string} memDump
  7. */
  8. function parseInput(memDump) {
  9. return Array.from(memDump.matchAll(/(mul\(\d{1,3},\d{1,3}\))/g));
  10. }
  11. function solve(validInstructions) {
  12. let sum = 0;
  13. for(const inst of validInstructions) {
  14. sum += eval(inst[0]);
  15. }
  16. console.log("Sum of result of valid instructions:", sum);
  17. }
  18. function mul(a,b) { return a*b; }