mirror of
https://github.com/javalsai/aoc.git
synced 2026-01-13 01:19:59 +01:00
day 3
had to speedrun that this morning on termux, its not even properly indented
This commit is contained in:
21
2024/02/p2/index.js
Normal file
21
2024/02/p2/index.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const readline = require('readline');
|
||||||
|
|
||||||
|
async function processLineByLine() {
|
||||||
|
const fileStream = fs.createReadStream('input.txt');
|
||||||
|
|
||||||
|
const rl = readline.createInterface({
|
||||||
|
input: fileStream,
|
||||||
|
crlfDelay: Infinity
|
||||||
|
});
|
||||||
|
|
||||||
|
let t = 0
|
||||||
|
for await (const line of rl) {
|
||||||
|
let m = line.match(/mul\([0-9]{1,3}, ?[0-9]{1,3}\)/g);
|
||||||
|
m = m.map(e => e.split('(')[1].split(')')[0].split(','))
|
||||||
|
.forEach(([a,b]) => t+=-a*-b)
|
||||||
|
}
|
||||||
|
console.log(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
processLineByLine();
|
||||||
Reference in New Issue
Block a user