18 lines
394 B
JavaScript
18 lines
394 B
JavaScript
|
#!/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);
|