Add 2024/day1/part2.js
This commit is contained in:
parent
57861f4a72
commit
5a7f354ead
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const list1=[];
|
||||
const list2=[];
|
||||
|
||||
require('fs').readFileSync('input.txt','utf8').split('\n').filter(i=>i).forEach(line=>{
|
||||
const parts = line.split(' ').map(i=>parseInt(i));
|
||||
list1.push(parts[0]);
|
||||
list2.push(parts[1]);
|
||||
});
|
||||
|
||||
const counts = require('lodash').countBy(list2);
|
||||
|
||||
var absurdscore=0;
|
||||
for(let num of list1) {
|
||||
absurdscore+=num*(counts[num]||0);
|
||||
}
|
||||
|
||||
console.log('Result:',absurdscore);
|
Loading…
Reference in New Issue