-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
69 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Submodule resources
updated
from 967c01 to 1541ba
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters