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 ad47f1d + 518f9de commit 51710be
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 5 deletions.
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.07",
"version": "2024.12.08",
"description": "Travis's Advent of Code 2024",
"author": "Travis Hardiman",
"homepage": "https://github.com/dieseltravis/aoc2024/",
Expand Down
105 changes: 103 additions & 2 deletions public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,109 @@
}
},
day8: {
part1: d => d,
part2: d => d
part1: (data) => {
const ants = {};
const output = [];
const input = data.trim().split('\n').map((r, y) => {
const row = r.split('');
const o = [];
row.forEach((c, x) => {
if (c !== '.') {
ants[c] = ants[c] || [];
ants[c].push({ y, x });
}
o.push('.');
});
output.push(o);
return row;
});
const ymax = input.length;
const xmax = input[0].length;
const inRange = p => p.y >= 0 && p.y < ymax && p.x >= 0 && p.x < xmax;
console.log(ants, input, ymax, xmax);
const anti = [];
Object.keys(ants).forEach(a => {
console.log('antenna ' + a);
const aa = ants[a];
const len = aa.length;
aa.forEach((p1, i) => {
// compare each remaining points
for (let j = i + 1; j < len; j++) {
const p2 = aa[j];
const dy = p2.y - p1.y;
const dx = p2.x - p1.x;
const anti1 = { a, y: p1.y - dy, x: p1.x - dx };
const anti2 = { a, y: p2.y + dy, x: p2.x + dx };
if (inRange(anti1)) {
anti.push(anti1);
output[anti1.y][anti1.x] = '#';
}
if (inRange(anti2)) {
anti.push(anti2);
output[anti2.y][anti2.x] = '#';
}
}
});
});
const mapped = output.map(r => r.join('')).join('\n');
console.log('antinodes:\n' + mapped);
return mapped.match(/#/g).length;
},
part2: (data) => {
const ants = {};
const output = [];
const input = data.trim().split('\n').map((r, y) => {
const row = r.split('');
const o = [];
row.forEach((c, x) => {
if (c !== '.') {
ants[c] = ants[c] || [];
ants[c].push({ y, x });
}
o.push('.');
});
output.push(o);
return row;
});
const ymax = input.length;
const xmax = input[0].length;
const inRange = p => p.y >= 0 && p.y < ymax && p.x >= 0 && p.x < xmax;
console.log(ants, input, ymax, xmax);
const anti = [];
Object.keys(ants).forEach(a => {
console.log('antenna ' + a);
const aa = ants[a];
const len = aa.length;
if (len > 1) {
aa.forEach((p1, i) => {
output[p1.y][p1.x] = '#';
// compare each remaining points
for (let j = i + 1; j < len; j++) {
const p2 = aa[j];
const dy = p2.y - p1.y;
const dx = p2.x - p1.x;
let anti1 = { a, y: p1.y - dy, x: p1.x - dx };
let anti2 = { a, y: p2.y + dy, x: p2.x + dx };
while (inRange(anti1)) {
anti.push(anti1);
output[anti1.y][anti1.x] = '#';
anti1 = { a, y: anti1.y - dy, x: anti1.x - dx };
}
while (inRange(anti2)) {
anti.push(anti2);
output[anti2.y][anti2.x] = '#';
anti2 = { a, y: anti2.y + dy, x: anti2.x + dx };
}
}
});
}
});
const mapped = output.map(r => r.join('')).join('\n');
console.log(anti.length, 'antinodes:\n' + mapped);
// 1042 is too low
// 1230 is too high
return mapped.match(/#/g).length;
}
},
day9: {
part1: d => d,
Expand Down
4 changes: 2 additions & 2 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ <h2>solutions:</h2>
<li><a href="/day/04">day 04</a></li>
<li><a href="/day/05">day 05</a></li>
<li><a href="/day/06">day 06</a></li>
<!--
<li><a href="/day/06">day 06</a>(part 2 broken)</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>
<li><a href="/day/11">day 11</a></li>
Expand Down

0 comments on commit 51710be

Please sign in to comment.