Created
December 1, 2024 17:19
-
-
Save manthanabc/ff1ed66927e5edd3baf48617e55ff619 to your computer and use it in GitHub Desktop.
AOC javascript in browser
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
t=document.getElementsByTagName("pre")[0].innerHTML.split('\n') | |
t.pop() | |
a=[] | |
b=[] | |
t.forEach((q) => { | |
let [x, _, __, z] = q.split(' '); | |
a.push(x) | |
b.push(z) | |
}) | |
a = a.sort(); | |
b = b.sort(); | |
let ans1=0, ans2=0; | |
for(let i=0; i<1000; i++) { | |
ans1 += Math.abs(a[i]-b[i]); | |
} | |
a.forEach((y) => ans2+=y*(b.filter((o) => o == y).length||0) ); | |
console.log(`Ans1: ${ans1}\nAns2: ${ans2}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment