Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glitch day 9 #17

Merged
merged 4 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ also on github: [dieseltravis/aoc2023](https://github.com/dieseltravis/aoc2023)
6. [day six](https://branch-three-oviraptor.glitch.me/day/06)
7. [day seven](https://branch-three-oviraptor.glitch.me/day/07) part 2 wip
8. [day eight](https://branch-three-oviraptor.glitch.me/day/08) part 2 wip
<!--
9. [day nine](https://branch-three-oviraptor.glitch.me/day/09)
<!--
10. [day ten](https://branch-three-oviraptor.glitch.me/day/10)
11. [day eleven](https://branch-three-oviraptor.glitch.me/day/11)
12. [day twelve](https://branch-three-oviraptor.glitch.me/day/12)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "branch-three-oviraptor",
"version": "2023.12.08",
"version": "2023.12.09",
"description": "Travis's Advent of Code 2023",
"author": "Travis Hardiman",
"homepage": "https://branch-three-oviraptor.glitch.me/",
Expand Down Expand Up @@ -34,8 +34,8 @@
],
"browserslist": [
"defaults",
"not IE 11",
"supports es6-module",
"node > 14",
"fully supports es6-module",
"maintained node versions"
]
}
155 changes: 83 additions & 72 deletions public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@
return c;
},
part2: (data) => {
// const gcd = (a, b) => !b ? a : gcd(b, a % b);
// const lcm = (a, b) => (a * b) / gcd(a, b);
const input = data.trim().split('\n\n');
const directions = input[0].trim().split('');
const map = input[1].trim().split('\n').reduce((m, line) => {
Expand All @@ -646,13 +648,14 @@
return m;
}, {});
const nodes = Object.keys(map).filter(m => m[2] === 'A');
console.log(nodes, directions, map);
const zzz = n => n[2] === 'Z';
const dlen = directions.length;
const nlen = nodes.length;
const starts = nodes.slice();
console.log(nodes, directions, map, starts);
let safety = 10000000000;
let i = 0;
let c = 0;
let safety = 10000000000;
while (!nodes.every(zzz) && safety-- > 0) {
i = i % dlen;
const d = directions[i];
Expand All @@ -671,109 +674,117 @@
},
day9: {
part1: (data) => {
return data;
const input = data.trim().split('\n').map(l => l.split(' ').map(Number));
const allEq = (val, _i, arr) => val === arr[0];
console.log(input);
const extra = [];
input.forEach(row => {
const agg = [row.slice()];
let cycle = 0;
let safety = 100;
do {
agg[cycle + 1] = [];
for (let l = agg[cycle].length - 1; l > 0; l--) {
agg[cycle + 1].unshift(agg[cycle][l] - agg[cycle][l - 1]);
}
cycle++;
} while (!agg[cycle].every(allEq) && safety--);
if (safety <= 0) {
console.warn('safety.');
}
// console.log(agg);
const sum = agg.reduce((acc, set) => acc + set[set.length - 1], 0);
extra.push(sum);
});
console.log(extra);
return extra.reduce((sum, val) => sum + val, 0);
},
part2: (data) => {
return data;
const input = data.trim().split('\n').map(l => l.split(' ').map(Number));
const allEq = (val, _i, arr) => val === arr[0];
console.log(input);
const extra = [];
input.forEach(row => {
const agg = [row.slice()];
let cycle = 0;
let safety = 100;
do {
agg[cycle + 1] = [];
for (let l = agg[cycle].length - 1; l > 0; l--) {
agg[cycle + 1].unshift(agg[cycle][l] - agg[cycle][l - 1]);
}
cycle++;
} while (!agg[cycle].every(allEq) && safety--);
if (safety <= 0) {
console.warn('safety.');
}
// console.log(agg);
const sub = agg.reverse().reduce((acc, set) => -acc + set[0], 0);
extra.push(sub);
});
console.log(extra);
return extra.reduce((sum, val) => sum + val, 0);
}
},
day10: {
part1: (data) => {
return data;
},
part2: (data) => {
return data;
}
part1: d => d,
part2: d => d
},
day11: {
part1: (data) => {
return data;
},
part2: (data) => {
return data;
}
part1: d => d,
part2: d => d
},
day12: {
part1: (data) => {
return data;
},
part2: (data) => {
return data;
}
part1: d => d,
part2: d => d
},
day13: {
part1: (data) => {
return data;
},
part2: (data) => {
return data;
}
part1: d => d,
part2: d => d
},
day14: {
part1: (data) => {
return data;
},
part2: (data) => {
return data;
}
part1: d => d,
part2: d => d
},
day15: {
part1: (data) => {
return data;
},
part2: (data) => {
return data;
}
part1: d => d,
part2: d => d
},
day16: {
part1: (data) => {
return data;
},
part2: () => {}
part1: d => d,
part2: d => d
},
day17: {
part1: (data) => {
return data;
},
part2: () => {}
part1: d => d,
part2: d => d
},
day18: {
part1: (data) => {
return data;
},
part2: () => {}
part1: d => d,
part2: d => d
},
day19: {
part1: (data) => {
return data;
},
part2: () => {}
part1: d => d,
part2: d => d
},
day20: {
part1: (data) => {
return data;
},
part2: () => {}
part1: d => d,
part2: d => d
},
day21: {
part1: (data) => {
return data;
},
part2: (data) => {
return data;
}
part1: d => d,
part2: d => d
},
day22: {
part1: (d) => { return d; },
part2: (d) => { return d; }
part1: d => d,
part2: d => d
},
day23: {
part1: (d) => { return d; },
part2: (d) => { return d; }
part1: d => d,
part2: d => d
},
day24: {
part1: (d) => { return d; },
part2: (d) => { return d; }
part1: d => d,
part2: d => d
},
day25: {
part1: d => d,
Expand Down
2 changes: 1 addition & 1 deletion views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ <h2>solutions:</h2>
<li><a href="/day/06">day 06</a></li>
<li><a href="/day/07">day 07</a> part 2 wip</li>
<li><a href="/day/08">day 08</a> part 2 wip</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>
<li><a href="/day/12">day 12</a></li>
Expand Down
Loading