From 5a7f354eadd672f0690607f7d69329b6c333fc2f Mon Sep 17 00:00:00 2001 From: x0x7 Date: Sun, 1 Dec 2024 08:50:53 -0500 Subject: [PATCH] Add 2024/day1/part2.js --- 2024/day1/part2.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 2024/day1/part2.js diff --git a/2024/day1/part2.js b/2024/day1/part2.js new file mode 100644 index 0000000..0c52cd3 --- /dev/null +++ b/2024/day1/part2.js @@ -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); \ No newline at end of file