Skip to content

Commit 0ebece5

Browse files
committed
Year 2024, Day 1
1 parent 427b289 commit 0ebece5

File tree

2 files changed

+1025
-0
lines changed

2 files changed

+1025
-0
lines changed

clients/typescript/solutions/S2401.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import ISolution from "./ISolution.ts";
2+
3+
export default class S2401 implements ISolution {
4+
firstPart(input: string): (number | string) | Promise<number | string> {
5+
const lists = input.split("\n").map(x => x.split(" ")).filter(x => x.length === 2);
6+
const list1 = lists.map(x => Number(x[0])).sort();
7+
const list2 = lists.map(x => Number(x[1])).sort();
8+
let sum = 0;
9+
for (let i = 0; i < list1.length; i++) {
10+
sum += Math.abs(list1[i] - list2[i]);
11+
}
12+
return sum;
13+
}
14+
secondPart(input: string): (number | string) | Promise<number | string> {
15+
const lists = input.split("\n").map(x => x.split(" ")).filter(x => x.length === 2);
16+
const list1 = lists.map(x => Number(x[0]));
17+
const list2 = lists.map(x => Number(x[1]));
18+
let sum = 0;
19+
for (const number of list1) {
20+
sum += number*list2.filter(x => x === number).length;
21+
}
22+
return sum;
23+
}
24+
25+
}

0 commit comments

Comments
 (0)