Skip to content

Commit f8d4433

Browse files
committed
style: fmt
1 parent 59a0e74 commit f8d4433

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

day11_test.ts

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,28 @@ Deno.test("Day 11: Cosmic Expansion", async (t) => {
2121
`..........`,
2222
`.......#..`,
2323
`#...#.....`,
24-
]),
25-
),
26-
).map(([, , length]) => length),
24+
])
25+
)
26+
).map(([, , length]) => length)
2727
),
28-
374,
29-
));
28+
374
29+
)
30+
);
3031

3132
await t.step("it should solve", async () =>
3233
assertEquals(
3334
sum(
3435
galaxyPathes(
3536
expandPositions(
3637
galaxyPositions(
37-
(await Deno.readTextFile("./input/day11.txt")).split("\n"),
38-
),
39-
),
40-
).map(([, , length]) => length),
38+
(await Deno.readTextFile("./input/day11.txt")).split("\n")
39+
)
40+
)
41+
).map(([, , length]) => length)
4142
),
42-
10165598,
43-
));
43+
10165598
44+
)
45+
);
4446
});
4547

4648
await t.step("Part 2", async (t) => {
@@ -61,12 +63,13 @@ Deno.test("Day 11: Cosmic Expansion", async (t) => {
6163
`.......#..`,
6264
`#...#.....`,
6365
]),
64-
10,
65-
),
66-
).map(([, , length]) => length),
66+
10
67+
)
68+
).map(([, , length]) => length)
6769
),
68-
1030,
69-
));
70+
1030
71+
)
72+
);
7073

7174
await t.step("Example 2", () =>
7275
assertEquals(
@@ -85,27 +88,29 @@ Deno.test("Day 11: Cosmic Expansion", async (t) => {
8588
`.......#..`,
8689
`#...#.....`,
8790
]),
88-
100,
89-
),
90-
).map(([, , length]) => length),
91+
100
92+
)
93+
).map(([, , length]) => length)
9194
),
92-
8410,
93-
));
95+
8410
96+
)
97+
);
9498

9599
await t.step("it should solve", async () =>
96100
assertEquals(
97101
sum(
98102
galaxyPathes(
99103
expandPositions(
100104
galaxyPositions(
101-
(await Deno.readTextFile("./input/day11.txt")).split("\n"),
105+
(await Deno.readTextFile("./input/day11.txt")).split("\n")
102106
),
103-
1000000,
104-
),
105-
).map(([, , length]) => length),
107+
1000000
108+
)
109+
).map(([, , length]) => length)
106110
),
107-
678728808158,
108-
));
111+
678728808158
112+
)
113+
);
109114
});
110115

111116
await t.step("galaxyPositions()", () =>
@@ -132,8 +137,9 @@ Deno.test("Day 11: Cosmic Expansion", async (t) => {
132137
[8, 7],
133138
[9, 0],
134139
[9, 4],
135-
],
136-
));
140+
]
141+
)
142+
);
137143

138144
await t.step("expandPositions()", () =>
139145
assertEquals(
@@ -149,7 +155,7 @@ Deno.test("Day 11: Cosmic Expansion", async (t) => {
149155
`..........`,
150156
`.......#..`,
151157
`#...#.....`,
152-
]),
158+
])
153159
),
154160
galaxyPositions([
155161
`....#........`,
@@ -164,8 +170,9 @@ Deno.test("Day 11: Cosmic Expansion", async (t) => {
164170
`.............`,
165171
`.........#...`,
166172
`#....#.......`,
167-
]),
168-
));
173+
])
174+
)
175+
);
169176
});
170177

171178
type Path = [from: [number, number], to: [number, number], length: number];
@@ -180,10 +187,10 @@ const galaxyPositions = (galaxy: Array<string>): Array<[number, number]> =>
180187
.reduce<Array<[number, number]>>(
181188
(galaxies, maybeGalaxy, col) =>
182189
isGalaxy(maybeGalaxy) ? [...galaxies, [row, col]] : galaxies,
183-
[],
190+
[]
184191
),
185192
],
186-
[],
193+
[]
187194
)
188195
.flat();
189196

@@ -197,7 +204,7 @@ const isGalaxy = (square: string): boolean => square === "#";
197204

198205
const expandPositions = (
199206
galaxies: Array<[number, number]>,
200-
amount = 1,
207+
amount = 1
201208
): Array<[number, number]> => {
202209
const cols = galaxies.map(([, col]) => col).sort((a, b) => a - b);
203210
const left = cols[0];
@@ -221,7 +228,7 @@ const expandPositions = (
221228
let colShift = 0;
222229
for (const col of colsWithOutGalaxies) {
223230
for (let g = 0; g < galaxies.length; g++) {
224-
// Move all galaxies right of col
231+
// Move all galaxies right of the col
225232
if (galaxies[g][1] > col + colShift) {
226233
galaxies[g][1] += Math.max(amount - 1, 1);
227234
}
@@ -233,11 +240,12 @@ const expandPositions = (
233240
let rowShift = 0;
234241
for (const row of rowsWithoutGalaxies) {
235242
for (let g = 0; g < galaxies.length; g++) {
236-
// Move all galaxies bottom of col
243+
// Move all galaxies below the row
237244
if (galaxies[g][0] > row + rowShift) {
238245
galaxies[g][0] += Math.max(amount - 1, 1);
239246
}
240247
}
248+
// The next shifts are cumulative
241249
rowShift += Math.max(amount - 1, 1);
242250
}
243251
return shifted;

0 commit comments

Comments
 (0)