Skip to content

Commit

Permalink
chore: cleaned up around 2023 day 11
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAegis committed Dec 11, 2023
1 parent f30c5ad commit bd41fa4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 63 deletions.
42 changes: 26 additions & 16 deletions solutions/typescript/2023/11/src/p1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@ import { BoundingBox, task } from '@alexaegis/advent-of-code-lib';
import packageJson from '../package.json';
import { parse } from './parse.js';

export const p1 = (input: string): number => {
const { galaxies, emptyRows, emptyColumns } = parse(input);
export const solver =
(expansion = 2) =>
(input: string): number => {
const { galaxies, emptyRows, emptyColumns } = parse(input);

return galaxies
.pairs()
.map(([a, b]) => {
const nonExpandedDistance = a.manhattan(b);
const galaxyBox = BoundingBox.fromVectors([a, b]);
const emptyRowCount = emptyRows.filter((i) => galaxyBox.vertical.contains(i)).length;
const emptyColumnCount = emptyColumns.filter((i) =>
galaxyBox.horizontal.contains(i),
).length;
return galaxies
.pairs()
.map(([a, b]) => {
const nonExpandedDistance = a.manhattan(b);
const galaxyBox = BoundingBox.fromVectors([a, b]);
const emptyRowCount = emptyRows.filter((i) =>
galaxyBox.vertical.contains(i),
).length;
const emptyColumnCount = emptyColumns.filter((i) =>
galaxyBox.horizontal.contains(i),
).length;

return nonExpandedDistance + emptyRowCount + emptyColumnCount;
})
.sum();
};
return (
nonExpandedDistance +
emptyRowCount * (expansion - 1) +
emptyColumnCount * (expansion - 1)
);
})
.sum();
};

await task(p1, packageJson.aoc); // 10228230 ~0ms
export const p1 = (input: string): number => solver(2)(input);

await task(p1, packageJson.aoc); // 10228230 ~104.54ms
24 changes: 4 additions & 20 deletions solutions/typescript/2023/11/src/p2.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { BoundingBox, task } from '@alexaegis/advent-of-code-lib';
import { task } from '@alexaegis/advent-of-code-lib';
import packageJson from '../package.json';
import { parse } from './parse.js';
import { solver } from './p1.js';

export const p2 = (input: string): number => {
const { galaxies, emptyRows, emptyColumns } = parse(input);
export const p2 = (input: string): number => solver(1_000_000)(input);

return galaxies
.pairs()
.map(([a, b]) => {
const nonExpandedDistance = a.manhattan(b);
const galaxyBox = BoundingBox.fromVectors([a, b]);
const emptyRowCount = emptyRows.filter((i) => galaxyBox.vertical.contains(i)).length;
const emptyColumnCount = emptyColumns.filter((i) =>
galaxyBox.horizontal.contains(i),
).length;

return nonExpandedDistance + emptyRowCount * 999_999 + emptyColumnCount * 999_999;
})
.sum();
};

await task(p2, packageJson.aoc); // 10228230 ~0ms
await task(p2, packageJson.aoc); // 10228230 ~104.48ms
54 changes: 27 additions & 27 deletions solutions/typescript/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@

<!-- markdownlint-disable MD013 -->

| Day | Part One | Part Two |
| ---------------------------------------- | -------------------------------------------------- | -------------------------------------------------- |
| [Day 1](/solutions/typescript/2023/01/) | [0.19ms](/solutions/typescript/2023/01/src/p1.ts) | [1.38ms](/solutions/typescript/2023/01/src/p2.ts) |
| [Day 2](/solutions/typescript/2023/02/) | [0.22ms](/solutions/typescript/2023/02/src/p1.ts) | [0.25ms](/solutions/typescript/2023/02/src/p2.ts) |
| [Day 3](/solutions/typescript/2023/03/) | [1.39ms](/solutions/typescript/2023/03/src/p1.ts) | [3.89ms](/solutions/typescript/2023/03/src/p2.ts) |
| [Day 4](/solutions/typescript/2023/04/) | [4.36ms](/solutions/typescript/2023/04/src/p1.ts) | [4.57ms](/solutions/typescript/2023/04/src/p2.ts) |
| [Day 5](/solutions/typescript/2023/05/) | [0.11ms](/solutions/typescript/2023/05/src/p1.ts) | [0.39ms](/solutions/typescript/2023/05/src/p2.ts) |
| [Day 6](/solutions/typescript/2023/06/) | [40μs](/solutions/typescript/2023/06/src/p1.ts) | [7μs](/solutions/typescript/2023/06/src/p2.ts) |
| [Day 7](/solutions/typescript/2023/07/) | [8.70ms](/solutions/typescript/2023/07/src/p1.ts) | [20.46ms](/solutions/typescript/2023/07/src/p2.ts) |
| [Day 8](/solutions/typescript/2023/08/) | [10.25ms](/solutions/typescript/2023/08/src/p1.ts) | [11.44ms](/solutions/typescript/2023/08/src/p2.ts) |
| [Day 9](/solutions/typescript/2023/09/) | [1.57ms](/solutions/typescript/2023/09/src/p1.ts) | [1.62ms](/solutions/typescript/2023/09/src/p2.ts) |
| [Day 10](/solutions/typescript/2023/10/) | [68.44ms](/solutions/typescript/2023/10/src/p1.ts) | [1.4s](/solutions/typescript/2023/10/src/p2.ts) |
| [Day 11](/solutions/typescript/2023/11/) | [0ms](/solutions/typescript/2023/11/src/p1.ts) | [0ms](/solutions/typescript/2023/11/src/p2.ts) |
| Day 12 | - | - |
| Day 13 | - | - |
| Day 14 | - | - |
| Day 15 | - | - |
| Day 16 | - | - |
| Day 17 | - | - |
| Day 18 | - | - |
| Day 19 | - | - |
| Day 20 | - | - |
| Day 21 | - | - |
| Day 22 | - | - |
| Day 23 | - | - |
| Day 24 | - | - |
| Day 25 | - | - |
| Day | Part One | Part Two |
| ---------------------------------------- | --------------------------------------------------- | --------------------------------------------------- |
| [Day 1](/solutions/typescript/2023/01/) | [0.19ms](/solutions/typescript/2023/01/src/p1.ts) | [1.38ms](/solutions/typescript/2023/01/src/p2.ts) |
| [Day 2](/solutions/typescript/2023/02/) | [0.22ms](/solutions/typescript/2023/02/src/p1.ts) | [0.25ms](/solutions/typescript/2023/02/src/p2.ts) |
| [Day 3](/solutions/typescript/2023/03/) | [1.39ms](/solutions/typescript/2023/03/src/p1.ts) | [3.89ms](/solutions/typescript/2023/03/src/p2.ts) |
| [Day 4](/solutions/typescript/2023/04/) | [4.36ms](/solutions/typescript/2023/04/src/p1.ts) | [4.57ms](/solutions/typescript/2023/04/src/p2.ts) |
| [Day 5](/solutions/typescript/2023/05/) | [0.11ms](/solutions/typescript/2023/05/src/p1.ts) | [0.39ms](/solutions/typescript/2023/05/src/p2.ts) |
| [Day 6](/solutions/typescript/2023/06/) | [40μs](/solutions/typescript/2023/06/src/p1.ts) | [7μs](/solutions/typescript/2023/06/src/p2.ts) |
| [Day 7](/solutions/typescript/2023/07/) | [8.70ms](/solutions/typescript/2023/07/src/p1.ts) | [20.46ms](/solutions/typescript/2023/07/src/p2.ts) |
| [Day 8](/solutions/typescript/2023/08/) | [10.25ms](/solutions/typescript/2023/08/src/p1.ts) | [11.44ms](/solutions/typescript/2023/08/src/p2.ts) |
| [Day 9](/solutions/typescript/2023/09/) | [1.57ms](/solutions/typescript/2023/09/src/p1.ts) | [1.62ms](/solutions/typescript/2023/09/src/p2.ts) |
| [Day 10](/solutions/typescript/2023/10/) | [68.44ms](/solutions/typescript/2023/10/src/p1.ts) | [1.4s](/solutions/typescript/2023/10/src/p2.ts) |
| [Day 11](/solutions/typescript/2023/11/) | [104.54ms](/solutions/typescript/2023/11/src/p1.ts) | [104.48ms](/solutions/typescript/2023/11/src/p2.ts) |
| Day 12 | - | - |
| Day 13 | - | - |
| Day 14 | - | - |
| Day 15 | - | - |
| Day 16 | - | - |
| Day 17 | - | - |
| Day 18 | - | - |
| Day 19 | - | - |
| Day 20 | - | - |
| Day 21 | - | - |
| Day 22 | - | - |
| Day 23 | - | - |
| Day 24 | - | - |
| Day 25 | - | - |

<!-- markdownlint-enable MD013 -->

Expand Down

0 comments on commit bd41fa4

Please sign in to comment.