Skip to content

Commit

Permalink
Merge pull request #1 from dieseltravis/day01
Browse files Browse the repository at this point in the history
day 1
  • Loading branch information
dieseltravis authored Dec 1, 2024
2 parents 644fc5d + 8856b44 commit 2a30ed2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 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
42 changes: 40 additions & 2 deletions public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,46 @@

const all = {
day1: {
part1: d => d,
part2: 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: (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.scores = split.left.reduce((acc, lnum) => {
acc.push(lnum * split.right.filter((rnum) => rnum === lnum).length);
return acc;
}, []);
console.log(split);
const sum = split.scores.reduce((acc, d) => acc + d, 0);
return sum;
}
},
day2: {
part1: d => d,
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 2a30ed2

Please sign in to comment.