From e44ff953cb7e467fc161f4f0175f5f1ebf801f51 Mon Sep 17 00:00:00 2001 From: x0x7 Date: Tue, 3 Dec 2024 10:03:03 -0500 Subject: [PATCH] Add 2024/day3/part1.js --- 2024/day3/part1.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 2024/day3/part1.js diff --git a/2024/day3/part1.js b/2024/day3/part1.js new file mode 100644 index 0000000..5bc6f74 --- /dev/null +++ b/2024/day3/part1.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +var content = require('fs').readFileSync(process.argv[2],'utf8'); + +var mulregex = /mul\((\d{1,3}),(\d{1,3})\)/g +var numregex = /\d+/g + + +var muls = content.match(mulregex); +var sum=0; +for(var mul of muls) { + var digits = mul.match(numregex); + var values = digits.map(i=>parseInt(i)); + //console.log({digits,values}); + sum+=values[0]*values[1]; +} + +console.log('Result:',sum); \ No newline at end of file