Last active
November 21, 2025 06:52
-
-
Save dominicgan/6ebc62caca5359693eca5ae20865da7f to your computer and use it in GitHub Desktop.
Advent of code 2024 Day 1
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
| const input = await fetch('https://adventofcode.com/2024/day/1/input').then(res => res.text()).then(data => data.trim()); | |
| console.log(input); | |
| const aArr = []; | |
| const bArr = []; | |
| input.split('\n').forEach((lineValue) => { | |
| const [a, b] = lineValue.split(' '); | |
| aArr.push(parseInt(a, 10)); | |
| bArr.push(parseInt(b, 10)); | |
| }); | |
| console.log(aArr, bArr) | |
| // part 2 | |
| const similarity = aArr.reduce((acc, val, i) => { | |
| const occurrences = bArr.filter((v2) => v2 === val).length | |
| return acc + val * occurrences; | |
| }, 0); | |
| console.log({similarity}) | |
| // part 1 | |
| // const aSortArr = aArr.sort((a,b) => a-b); | |
| // const bSortArr = bArr.sort((a,b) => a-b); | |
| // console.log(aSortArr, bSortArr) | |
| // const distanceArr = aSortArr.map((val, index) => { | |
| // return Math.abs(val - bSortArr[index]) | |
| // }) | |
| // console.log(distanceArr) | |
| // const distance = distanceArr.reduce((acc, cur) => acc+cur, 0) | |
| // console.log(distance) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment