diff --git a/src/2023/day11.js b/src/2023/day11.js index df469fa5..babf7ed1 100644 --- a/src/2023/day11.js +++ b/src/2023/day11.js @@ -2,8 +2,7 @@ export function part1(input, add = 1) { const map = input.split('\n').map(line => line.split('')); let stars = map .flatMap((row, y) => row.map((cell, x) => ({ cell, x, y }))) - .filter(({ cell }) => cell === '#') - .map((c, i) => ({ ...c, id: i + 1 })); + .filter(({ cell }) => cell === '#'); let ydiff = 0; for (let y = 0; y < map.length; y++) { if (map[y].every(c => c === '.')) { @@ -18,16 +17,12 @@ export function part1(input, add = 1) { xdiff += add; } } - const length = stars - .map((cell, i) => { - return stars.slice(i + 1).reduce((acc, other) => { - const distance = - Math.abs(cell.x - other.x) + Math.abs(cell.y - other.y); - return acc + distance; - }, 0); - }) - .reduce((a, b) => a + b); - return length; + const distances = stars.map((a, i) => + stars + .slice(i + 1) + .reduce((acc, b) => acc + Math.abs(a.x - b.x) + Math.abs(a.y - b.y), 0), + ); + return distances.reduce((a, b) => a + b); } export function part2(input) {