Skip to content

Commit

Permalink
Add day 17 of year 2024 🤶
Browse files Browse the repository at this point in the history
  • Loading branch information
letelete committed Dec 17, 2024
1 parent 4647b41 commit 3fa58fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions 2024/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
| [13](./days/day-13) | ![gold-star](../assets/star-gold.svg) ![gold-star](../assets/star-gold.svg) | 1.27ms \| 0.15ms | [Open on AoC](https://adventofcode.com/2024/day/13) |
| [14](./days/day-14) | ![gold-star](../assets/star-gold.svg) ![gold-star](../assets/star-gold.svg) | 0.19ms \| 645.41ms | [Open on AoC](https://adventofcode.com/2024/day/14) |
| [16](./days/day-16) | ![gold-star](../assets/star-gold.svg) ![gold-star](../assets/star-gold.svg) | 10.97ms \| 8.328s | [Open on AoC](https://adventofcode.com/2024/day/16) |
| [17](./days/day-17) | ![gold-star](../assets/star-gold.svg) ![gold-star](../assets/star-gold.svg) | 6.09ms \| 2.35ms | [Open on AoC](https://adventofcode.com/2024/day/17) |
| [17](./days/day-17) | ![gold-star](../assets/star-gold.svg) ![gold-star](../assets/star-gold.svg) | 11.14ms \| 5.96ms | [Open on AoC](https://adventofcode.com/2024/day/17) |

> Autogenerated using [Custom GitHub Action Workflow](https://github.com/letelete/advent-of-code/blob/496913f895327f7755c5f03117730239d2b912eb/.github/workflows/update-year-readme.yml).
> Made by [Bruno Kawka](https://kawka.me).
> Last update at Tue Dec 17 11:05:30 UTC 2024
> Last update at Tue Dec 17 11:09:32 UTC 2024
## AoC Bash Utility

Expand Down
8 changes: 4 additions & 4 deletions 2024/days/day-17/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Memory: 18.00 GB

## Answer

| part | time (~) | μs |
| ---- | -------- | ------------------ |
| 1 | 6.09ms | 6.088292000000003 |
| 2 | 2.35ms | 2.3469580000000008 |
| part | time (~) | μs |
| ---- | -------- | ----------------- |
| 1 | 11.50ms | 11.49562499999999 |
| 2 | 5.88ms | 5.879374999999996 |
25 changes: 10 additions & 15 deletions 2024/days/day-17/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,27 @@ function Computer({ reg: { a, b, c }, verbose }) {
}

function findMinAToOutputSelf({ reg: { b, c }, program }) {
const cache = new Map();

const lookup = (lowerBound, ptr) => {
const hash = `${lowerBound},${ptr}`;
if (cache.has(hash)) {
return cache.get(hash);
}
// If a1 >= a0 * 8, cmp.run with a=a1 retains the last digit of cmp.out for cmp.run with a=a0.
const lowerBound = (a) => 8 * a;
const upperBound = (a) => 8 * (a + 1) - 1;

const lookup = (a, ptr) => {
if (ptr < 0) {
return lowerBound;
return a;
}

for (let a = lowerBound * 8; a < (lowerBound + 1) * 8; ++a) {
const cmp = Computer({ reg: { a, b, c } });
for (let _a = lowerBound(a); _a <= upperBound(a); ++_a) {
const cmp = Computer({ reg: { a: _a, b, c } });
cmp.run(program);

if (cmp.state.out[0] === program[ptr]) {
const match = lookup(a, ptr - 1);
if (match >= 0) {
cache.set(hash, match);
return match;
const _alookup = lookup(_a, ptr - 1);
if (_alookup >= 0) {
return _alookup;
}
}
}

cache.set(hash, -1);
return -1;
};

Expand Down

0 comments on commit 3fa58fa

Please sign in to comment.