Skip to content

Commit

Permalink
feat: 2024 01
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAegis committed Dec 1, 2024
1 parent cb88ffe commit 84f71ef
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/badges/typescript/2024.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"label": "Advent of TypeScript 2024",
"message": "0/25",
"message": "1/25",
"color": "orange"
}
2 changes: 1 addition & 1 deletion resources
14 changes: 11 additions & 3 deletions solutions/typescript/2024/01/src/p1.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { task } from '@alexaegis/advent-of-code-lib';
import { ascending, task, zip } from '@alexaegis/advent-of-code-lib';
import packageJson from '../package.json' assert { type: 'json' };
import { parse } from './parse.js';

export const p1 = (input: string): number => {
return 0;
const { left, right } = parse(input);

left.sort(ascending);
right.sort(ascending);

return zip(left, right)
.map(([l, r]) => Math.abs(l - r))
.sum();
};
await task(p1, packageJson.aoc); // 0 ~0ms
await task(p1, packageJson.aoc); // 1722302 ~16.04ms
12 changes: 10 additions & 2 deletions solutions/typescript/2024/01/src/p2.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { task } from '@alexaegis/advent-of-code-lib';
import packageJson from '../package.json' assert { type: 'json' };
import { parse } from './parse.js';

export const p2 = (input: string): number => {
return 0;
const { left, right } = parse(input);

return left
.map((l) => {
const rigthAppearance = right.filter((r) => r === l).length;
return l * rigthAppearance;
})
.sum();
};

await task(p2, packageJson.aoc); // 0 ~0ms
await task(p2, packageJson.aoc); // 20373490 ~18.95ms
19 changes: 19 additions & 0 deletions solutions/typescript/2024/01/src/parse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { WHITESPACE } from '@alexaegis/advent-of-code-lib';

export interface SeparatedInput {
left: number[];
right: number[];
}

export const parse = (input: string): SeparatedInput =>
input
.lines()
.map((line) => line.splitIntoStringPair(WHITESPACE))
.reduce(
(acc, [left, right]) => {
acc.left.push(parseInt(left, 10));
acc.right.push(parseInt(right, 10));
return acc;
},
{ left: [], right: [] } as SeparatedInput,
);
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/2024/01/) | [0ms](/solutions/typescript/2024/01/src/p1.ts) | [0ms](/solutions/typescript/2024/01/src/p2.ts) |
| Day 2 | - | - |
| Day 3 | - | - |
| Day 4 | - | - |
| Day 5 | - | - |
| Day 6 | - | - |
| Day 7 | - | - |
| Day 8 | - | - |
| Day 9 | - | - |
| Day 10 | - | - |
| Day 11 | - | - |
| 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/2024/01/) | [16.04ms](/solutions/typescript/2024/01/src/p1.ts) | [18.95ms](/solutions/typescript/2024/01/src/p2.ts) |
| Day 2 | - | - |
| Day 3 | - | - |
| Day 4 | - | - |
| Day 5 | - | - |
| Day 6 | - | - |
| Day 7 | - | - |
| Day 8 | - | - |
| Day 9 | - | - |
| Day 10 | - | - |
| Day 11 | - | - |
| 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 84f71ef

Please sign in to comment.