Created
March 3, 2025 21:11
-
-
Save torbiak/9b8d4d60575ad48085ab48f4e3a4b10f to your computer and use it in GitHub Desktop.
Revisions
-
torbiak created this gist
Mar 3, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ const fs = require('node:fs'); const left: number[] = [], right: number[] = []; const input = fs.readFileSync('input', {encoding: 'utf8'}); for (const line of input.split(/\n/)) { if (line === '') continue; const [l, r] = line.split(/\s+/); left.push(Number(l)); right.push(Number(r)); } left.sort(); right.sort(); const distance = left.reduce((dist, l, i) => dist + Math.abs(l - right[i])); console.log(distance);