Skip to content

Commit

Permalink
day 1, part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
dieseltravis committed Dec 1, 2024
1 parent 644fc5d commit e433511
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ my 2024 solutions on ~~glitch: [meowing-holy-carbon](https://meowing-holy-carbon

also on github: [dieseltravis/aoc2024](https://github.com/dieseltravis/aoc2024)

[![Days completed in a row](https://img.shields.io/badge/⭐%20days%20in%20a%20row-16-blueviolet)](https://adventofcode.com/2024/) [![glitch](https://shields.io/badge/glitch-%F0%9F%91%8D%F0%9F%8E%8F-blue?logo=glitch&logoColor=violet)](https://glitch.com/)
[![Days completed in a row](https://img.shields.io/badge/⭐%20days%20in%20a%20row-01-blueviolet)](https://adventofcode.com/2024/)

[![Node.js CI](https://github.com/dieseltravis/aoc2024/actions/workflows/node.js.yml/badge.svg)](https://github.com/dieseltravis/aoc2024/actions/workflows/node.js.yml) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdieseltravis%2Faoc2024.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fdieseltravis%2Faoc2024?ref=badge_shield) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?logo=javascript)](https://github.com/standard/semistandard)

Expand Down
22 changes: 21 additions & 1 deletion public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@

const all = {
day1: {
part1: d => d,
part1: (data) => {
const input = data.trim().split('\n').map(r => {
const pair = r.split(' ').map(Number);
return pair;
});
console.log(input);
const split = input.reduce((acc, pair) => {
acc.left.push(pair[0]);
acc.right.push(pair[1]);
return acc;
}, { left: [], right: [] });
split.left.sort((a, b) => a - b);
split.right.sort((a, b) => a - b);
split.diff = split.left.reduce((acc, num, i) => {
acc.push(Math.abs(num - split.right[i]));
return acc;
}, []);
console.log(split);
const sum = split.diff.reduce((acc, d) => acc + d, 0);
return sum;
},
part2: d => d
},
day2: {
Expand Down
2 changes: 2 additions & 0 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ footer {
margin-top: 50px;
padding-top: 25px;
border-top: 1px solid lightgrey;
font-size: xx-small;
}

div.glitchButton {
display: none;
position: fixed;
top: 20px;
right: 20px;
Expand Down

0 comments on commit e433511

Please sign in to comment.