Skip to content

Instantly share code, notes, and snippets.

@bluepichu
Created December 1, 2024 05:10
Show Gist options
  • Save bluepichu/580e4838c369ebb1805e5d202bebb87a to your computer and use it in GitHub Desktop.
Save bluepichu/580e4838c369ebb1805e5d202bebb87a to your computer and use it in GitHub Desktop.
import { Advent, f, fm, chr, ord, isDigit } from "advent";
import { Set, Map } from "immutable";
const { compute, computeCheck } = await Advent({ day: 1 });
compute(2, async (input) => {
const data = input.parse(f.nl(f.splitWs(f.int())));
const arr1 = data.map((x) => x[0]);
const arr2 = data.map((x) => x[1]);
arr1.sort((a, b) => a - b);
arr2.sort((a, b) => a - b);
let ans = 0;
for (let i = 0; i < arr1.length; i++) {
// const a = arr1[i];
// const b = arr2[i];
// console.log(a, b, Math.abs(a - b));
// ans += Math.abs(a - b);
const x = arr2.filter((y) => y === arr1[i]).length;
ans += arr1[i] * x;
}
return ans;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment