Created
December 1, 2024 05:10
-
-
Save bluepichu/580e4838c369ebb1805e5d202bebb87a to your computer and use it in GitHub Desktop.
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 characters
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