Skip to content

Commit 84f71ef

Browse files
committed
feat: 2024 01
1 parent cb88ffe commit 84f71ef

File tree

6 files changed

+69
-34
lines changed

6 files changed

+69
-34
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"schemaVersion": 1,
33
"label": "Advent of TypeScript 2024",
4-
"message": "0/25",
4+
"message": "1/25",
55
"color": "orange"
66
}

resources

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import { task } from '@alexaegis/advent-of-code-lib';
1+
import { ascending, task, zip } from '@alexaegis/advent-of-code-lib';
22
import packageJson from '../package.json' assert { type: 'json' };
3+
import { parse } from './parse.js';
34

45
export const p1 = (input: string): number => {
5-
return 0;
6+
const { left, right } = parse(input);
7+
8+
left.sort(ascending);
9+
right.sort(ascending);
10+
11+
return zip(left, right)
12+
.map(([l, r]) => Math.abs(l - r))
13+
.sum();
614
};
7-
await task(p1, packageJson.aoc); // 0 ~0ms
15+
await task(p1, packageJson.aoc); // 1722302 ~16.04ms
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { task } from '@alexaegis/advent-of-code-lib';
22
import packageJson from '../package.json' assert { type: 'json' };
3+
import { parse } from './parse.js';
34

45
export const p2 = (input: string): number => {
5-
return 0;
6+
const { left, right } = parse(input);
7+
8+
return left
9+
.map((l) => {
10+
const rigthAppearance = right.filter((r) => r === l).length;
11+
return l * rigthAppearance;
12+
})
13+
.sum();
614
};
715

8-
await task(p2, packageJson.aoc); // 0 ~0ms
16+
await task(p2, packageJson.aoc); // 20373490 ~18.95ms
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { WHITESPACE } from '@alexaegis/advent-of-code-lib';
2+
3+
export interface SeparatedInput {
4+
left: number[];
5+
right: number[];
6+
}
7+
8+
export const parse = (input: string): SeparatedInput =>
9+
input
10+
.lines()
11+
.map((line) => line.splitIntoStringPair(WHITESPACE))
12+
.reduce(
13+
(acc, [left, right]) => {
14+
acc.left.push(parseInt(left, 10));
15+
acc.right.push(parseInt(right, 10));
16+
return acc;
17+
},
18+
{ left: [], right: [] } as SeparatedInput,
19+
);

solutions/typescript/readme.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@
66

77
<!-- markdownlint-disable MD013 -->
88

9-
| Day | Part One | Part Two |
10-
| --------------------------------------- | ---------------------------------------------- | ---------------------------------------------- |
11-
| [Day 1](/solutions/typescript/2024/01/) | [0ms](/solutions/typescript/2024/01/src/p1.ts) | [0ms](/solutions/typescript/2024/01/src/p2.ts) |
12-
| Day 2 | - | - |
13-
| Day 3 | - | - |
14-
| Day 4 | - | - |
15-
| Day 5 | - | - |
16-
| Day 6 | - | - |
17-
| Day 7 | - | - |
18-
| Day 8 | - | - |
19-
| Day 9 | - | - |
20-
| Day 10 | - | - |
21-
| Day 11 | - | - |
22-
| Day 12 | - | - |
23-
| Day 13 | - | - |
24-
| Day 14 | - | - |
25-
| Day 15 | - | - |
26-
| Day 16 | - | - |
27-
| Day 17 | - | - |
28-
| Day 18 | - | - |
29-
| Day 19 | - | - |
30-
| Day 20 | - | - |
31-
| Day 21 | - | - |
32-
| Day 22 | - | - |
33-
| Day 23 | - | - |
34-
| Day 24 | - | - |
35-
| Day 25 | - | - |
9+
| Day | Part One | Part Two |
10+
| --------------------------------------- | -------------------------------------------------- | -------------------------------------------------- |
11+
| [Day 1](/solutions/typescript/2024/01/) | [16.04ms](/solutions/typescript/2024/01/src/p1.ts) | [18.95ms](/solutions/typescript/2024/01/src/p2.ts) |
12+
| Day 2 | - | - |
13+
| Day 3 | - | - |
14+
| Day 4 | - | - |
15+
| Day 5 | - | - |
16+
| Day 6 | - | - |
17+
| Day 7 | - | - |
18+
| Day 8 | - | - |
19+
| Day 9 | - | - |
20+
| Day 10 | - | - |
21+
| Day 11 | - | - |
22+
| Day 12 | - | - |
23+
| Day 13 | - | - |
24+
| Day 14 | - | - |
25+
| Day 15 | - | - |
26+
| Day 16 | - | - |
27+
| Day 17 | - | - |
28+
| Day 18 | - | - |
29+
| Day 19 | - | - |
30+
| Day 20 | - | - |
31+
| Day 21 | - | - |
32+
| Day 22 | - | - |
33+
| Day 23 | - | - |
34+
| Day 24 | - | - |
35+
| Day 25 | - | - |
3636

3737
<!-- markdownlint-enable MD013 -->
3838

0 commit comments

Comments
 (0)