File tree Expand file tree Collapse file tree 6 files changed +69
-34
lines changed
.github/badges/typescript Expand file tree Collapse file tree 6 files changed +69
-34
lines changed Original file line number Diff line number Diff line change 11{
22 "schemaVersion" : 1 ,
33 "label" : " Advent of TypeScript 2024" ,
4- "message" : " 0 /25" ,
4+ "message" : " 1 /25" ,
55 "color" : " orange"
66}
Original file line number Diff line number Diff line change 1- import { task } from '@alexaegis/advent-of-code-lib' ;
1+ import { ascending , task , zip } from '@alexaegis/advent-of-code-lib' ;
22import packageJson from '../package.json' assert { type : 'json' } ;
3+ import { parse } from './parse.js' ;
34
45export 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
Original file line number Diff line number Diff line change 11import { task } from '@alexaegis/advent-of-code-lib' ;
22import packageJson from '../package.json' assert { type : 'json' } ;
3+ import { parse } from './parse.js' ;
34
45export 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
Original file line number Diff line number Diff line change 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+ ) ;
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments