@@ -10,18 +10,20 @@ Deno.test("Day 11: Cosmic Expansion", async (t) => {
1010 assertEquals (
1111 sum (
1212 galaxyPathes (
13- expand ( [
14- `...#......` ,
15- `.......#..` ,
16- `#.........` ,
17- `..........` ,
18- `......#...` ,
19- `.#........` ,
20- `.........#` ,
21- `..........` ,
22- `.......#..` ,
23- `#...#.....` ,
24- ] )
13+ galaxyPositions (
14+ expand ( [
15+ `...#......` ,
16+ `.......#..` ,
17+ `#.........` ,
18+ `..........` ,
19+ `......#...` ,
20+ `.#........` ,
21+ `.........#` ,
22+ `..........` ,
23+ `.......#..` ,
24+ `#...#.....` ,
25+ ] )
26+ )
2527 ) . map ( ( [ , , length ] ) => length )
2628 ) ,
2729 374
@@ -32,7 +34,11 @@ Deno.test("Day 11: Cosmic Expansion", async (t) => {
3234 assertEquals (
3335 sum (
3436 galaxyPathes (
35- expand ( ( await Deno . readTextFile ( "./input/day11.txt" ) ) . split ( "\n" ) )
37+ galaxyPositions (
38+ expand (
39+ ( await Deno . readTextFile ( "./input/day11.txt" ) ) . split ( "\n" )
40+ )
41+ )
3642 ) . map ( ( [ , , length ] ) => length )
3743 ) ,
3844 10165598
@@ -100,10 +106,9 @@ const rotateRight = (map: Array<string>): Array<string> =>
100106 rotateLeft ( rotateLeft ( rotateLeft ( map ) ) ) ;
101107
102108type Path = [ from : [ number , number ] , to : [ number , number ] , length : number ] ;
103- type Galaxy = Array < Array < string > > ;
104109
105- const galaxyPathes = ( galaxy : Array < string > ) : Path [ ] => {
106- const galaxies = galaxy
110+ const galaxyPositions = ( galaxy : Array < string > ) : Array < [ number , number ] > =>
111+ galaxy
107112 . reduce < Array < Array < [ number , number ] > > > (
108113 ( galaxies , rowString , row ) => [
109114 ...galaxies ,
@@ -119,13 +124,12 @@ const galaxyPathes = (galaxy: Array<string>): Path[] => {
119124 )
120125 . flat ( ) ;
121126
122- return uniqueCombinations < [ number , number ] > ( 2 ) ( galaxies ) . map ( ( [ from , to ] ) => [
127+ const galaxyPathes = ( galaxies : Array < [ number , number ] > ) : Path [ ] =>
128+ uniqueCombinations < [ number , number ] > ( 2 ) ( galaxies ) . map ( ( [ from , to ] ) => [
123129 from ,
124130 to ,
125131 manhattanDistance ( from , to ) ,
126132 ] ) ;
127- } ;
128-
129133const isGalaxy = ( square : string ) : boolean => square === "#" ;
130134
131135const expand = ( map : Array < string > ) : Array < string > => {
0 commit comments