Skip to content

Instantly share code, notes, and snippets.

@torbiak
Created March 3, 2025 21:11
Show Gist options
  • Save torbiak/9b8d4d60575ad48085ab48f4e3a4b10f to your computer and use it in GitHub Desktop.
Save torbiak/9b8d4d60575ad48085ab48f4e3a4b10f to your computer and use it in GitHub Desktop.
Advent of Code 2024: Day 1
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment