File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ describe('2025 Day 7', () => {
77 } ) ;
88
99 test ( 'Part 2' , async ( ) => {
10- // expect(await part2('testInput1')).toEqual(31 );
11- // expect(await part2('input')).toEqual(29379307 );
10+ expect ( await part2 ( 'testInput1' ) ) . toEqual ( 40 ) ;
11+ expect ( await part2 ( 'input' ) ) . toEqual ( 4509723641302 ) ;
1212 } ) ;
1313} ) ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export async function part1(inputFile: string) {
77}
88
99export async function part2 ( inputFile : string ) {
10- return await day7 ( inputFile ) ;
10+ return await day7 ( inputFile , findBeanSplitTimelines ) ;
1111}
1212
1313async function day7 ( inputFile : string , calcFn ?: ( grid : Grid , initialPos : Coord ) => number ) {
@@ -49,4 +49,25 @@ function findBeanSplits(grid: Grid, initialPos: Coord): number {
4949 }
5050
5151 return splits ;
52- }
52+ }
53+
54+ function findBeanSplitTimelines ( grid : Grid , initialPos : Coord ) : number {
55+ const memo = new Map < string , number > ( ) ;
56+
57+ function timelines ( coord : Coord ) : number {
58+ const key = coord . serialize ( ) ;
59+ if ( memo . has ( key ) ) return memo . get ( key ) ! ;
60+
61+ const cellValue = grid . get ( key ) ;
62+ if ( cellValue === undefined ) return 1 ;
63+
64+ const result = cellValue === '^'
65+ ? timelines ( move ( coord , Cardinal . WEST ) ) + timelines ( move ( coord , Cardinal . EAST ) )
66+ : timelines ( move ( coord , Cardinal . SOUTH ) ) ;
67+
68+ memo . set ( key , result ) ;
69+ return result ;
70+ }
71+
72+ return timelines ( move ( initialPos , Cardinal . SOUTH ) ) ;
73+ }
You can’t perform that action at this time.
0 commit comments