Skip to content

Commit

Permalink
Merge branch 'main' into day06
Browse files Browse the repository at this point in the history
  • Loading branch information
dieseltravis authored Dec 8, 2024
2 parents 60de13f + 212abf1 commit 1881182
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 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-5-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) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?logo=javascript)](https://github.com/standard/semistandard)
[![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) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?logo=javascript)](https://github.com/standard/semistandard)

## solutions:
Install node `>18.18.x`, `yarn`, run `yarn install`, and then `yarn start`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meowing-holy-carbon",
"version": "2024.12.06",
"version": "2024.12.07",
"description": "Travis's Advent of Code 2024",
"author": "Travis Hardiman",
"homepage": "https://github.com/dieseltravis/aoc2024/",
Expand Down
69 changes: 67 additions & 2 deletions public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,73 @@
}
},
day7: {
part1: d => d,
part2: d => d
part1: (data) => {
const input = data.trim().split('\n').map(r => {
const row = r.split(':').map(p => p.trim());
return {
key: +row[0],
vals: row[1].split(' ').map(Number)
};
});
console.log(input);
const ops = [
(a, b) => a + b,
(a, b) => a * b
];
const good = [];
for (let l = input.length; l--;) {
const key = input[l].key;
const vals = input[l].vals;
const valen = vals.length;
for (let dec = Math.pow(2, valen - 1); dec--;) {
const bin = dec.toString(2).padStart(valen - 1, '0').split('').map(Number);
let test = vals[0];
for (let i = 1; i < valen; i++) {
test = ops[bin[i - 1]](test, vals[i]);
}
if (key === test) {
good.push(key);
break;
}
}
}
const sum = good.reduce((acc, n) => acc + n, 0);
return sum;
},
part2: (data) => {
const input = data.trim().split('\n').map(r => {
const row = r.split(':').map(p => p.trim());
return {
key: +row[0],
vals: row[1].split(' ').map(Number)
};
});
console.log(input);
const ops = [
(a, b) => a + b,
(a, b) => a * b,
(a, b) => +(a + '' + b)
];
const good = [];
for (let l = input.length; l--;) {
const key = input[l].key;
const vals = input[l].vals;
const valen = vals.length;
for (let dec = Math.pow(3, valen - 1); dec--;) {
const bin = dec.toString(3).padStart(valen - 1, '0').split('').map(Number);
let test = vals[0];
for (let i = 1; i < valen; i++) {
test = ops[bin[i - 1]](test, vals[i]);
}
if (key === test) {
good.push(key);
break;
}
}
}
const sum = good.reduce((acc, n) => acc + n, 0);
return sum;
}
},
day8: {
part1: d => d,
Expand Down
1 change: 1 addition & 0 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ <h2>solutions:</h2>
<li><a href="/day/06">day 06</a></li>
<!--
<li><a href="/day/07">day 07</a></li>
<!--
<li><a href="/day/08">day 08</a></li>
<li><a href="/day/09">day 09</a></li>
<li><a href="/day/10">day 10</a></li>
Expand Down

0 comments on commit 1881182

Please sign in to comment.