Skip to content

Commit efe6aa8

Browse files
committed
Added day10 part 2
1 parent e74ec2d commit efe6aa8

File tree

7 files changed

+149
-2
lines changed

7 files changed

+149
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2023'
7-
version '0.9.2'
7+
version '0.9.3'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

day10/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,109 @@ Here are the distances for each tile on that loop:
118118
```
119119
Find the single giant loop starting at `S`. **How many steps along the loop does it take to get from the starting
120120
position to the point farthest from the starting position**?
121+
122+
# Part Two
123+
You quickly reach the farthest point of the loop, but the animal never emerges. Maybe its nest is **within the area
124+
enclosed by the loop**?
125+
126+
To determine whether it's even worth taking the time to search for such a nest, you should calculate how many tiles are
127+
contained within the loop. For example:
128+
```
129+
...........
130+
.S-------7.
131+
.|F-----7|.
132+
.||.....||.
133+
.||.....||.
134+
.|L-7.F-J|.
135+
.|..|.|..|.
136+
.L--J.L--J.
137+
...........
138+
```
139+
The above loop encloses merely **four tiles** - the two pairs of `.` in the southwest and southeast (marked `I` below).
140+
The middle `.` tiles (marked `O` below) are not in the loop. Here is the same loop again with those regions marked:
141+
```
142+
...........
143+
.S-------7.
144+
.|F-----7|.
145+
.||OOOOO||.
146+
.||OOOOO||.
147+
.|L-7OF-J|.
148+
.|II|O|II|.
149+
.L--JOL--J.
150+
.....O.....
151+
```
152+
In fact, there doesn't even need to be a full tile path to the outside for tiles to count as outside the loop -
153+
squeezing between pipes is also allowed! Here, `I` is still within the loop and `O` is still outside the loop:
154+
```
155+
..........
156+
.S------7.
157+
.|F----7|.
158+
.||OOOO||.
159+
.||OOOO||.
160+
.|L-7F-J|.
161+
.|II||II|.
162+
.L--JL--J.
163+
..........
164+
```
165+
In both of the above examples, **`4`** tiles are enclosed by the loop.
166+
167+
Here's a larger example:
168+
```
169+
.F----7F7F7F7F-7....
170+
.|F--7||||||||FJ....
171+
.||.FJ||||||||L7....
172+
FJL7L7LJLJ||LJ.L-7..
173+
L--J.L7...LJS7F-7L7.
174+
....F-J..F7FJ|L7L7L7
175+
....L7.F7||L7|.L7L7|
176+
.....|FJLJ|FJ|F7|.LJ
177+
....FJL-7.||.||||...
178+
....L---J.LJ.LJLJ...
179+
```
180+
The above sketch has many random bits of ground, some of which are in the loop (`I`) and some of which are outside it
181+
(`O`):
182+
```
183+
OF----7F7F7F7F-7OOOO
184+
O|F--7||||||||FJOOOO
185+
O||OFJ||||||||L7OOOO
186+
FJL7L7LJLJ||LJIL-7OO
187+
L--JOL7IIILJS7F-7L7O
188+
OOOOF-JIIF7FJ|L7L7L7
189+
OOOOL7IF7||L7|IL7L7|
190+
OOOOO|FJLJ|FJ|F7|OLJ
191+
OOOOFJL-7O||O||||OOO
192+
OOOOL---JOLJOLJLJOOO
193+
```
194+
In this larger example, **`8`** tiles are enclosed by the loop.
195+
196+
Any tile that isn't part of the main loop can count as being enclosed by the loop. Here's another example with many
197+
bits of junk pipe lying around that aren't connected to the main loop at all:
198+
```
199+
FF7FSF7F7F7F7F7F---7
200+
L|LJ||||||||||||F--J
201+
FL-7LJLJ||||||LJL-77
202+
F--JF--7||LJLJ7F7FJ-
203+
L---JF-JLJ.||-FJLJJ7
204+
|F|F-JF---7F7-L7L|7|
205+
|FFJF7L7F-JF7|JL---7
206+
7-L-JL7||F7|L7F-7F7|
207+
L.L7LFJ|||||FJL7||LJ
208+
L7JLJL-JLJLJL--JLJ.L
209+
```
210+
Here are just the tiles that are **enclosed by the loop** marked with `I`:
211+
```
212+
FF7FSF7F7F7F7F7F---7
213+
L|LJ||||||||||||F--J
214+
FL-7LJLJ||||||LJL-77
215+
F--JF--7||LJLJIF7FJ-
216+
L---JF-JLJIIIIFJLJJ7
217+
|F|F-JF---7IIIL7L|7|
218+
|FFJF7L7F-JF7IIL---7
219+
7-L-JL7||F7|L7F-7F7|
220+
L.L7LFJ|||||FJL7||LJ
221+
L7JLJL-JLJLJL--JLJ.L
222+
```
223+
In this last example, **`10`** tiles are enclosed by the loop.
224+
225+
Figure out whether you have time to search for the nest by calculating the area within the loop. **How many tiles are
226+
enclosed by the loop**?

day10/src/test/kotlin/de/havox_design/aoc2023/day10/Day10Test.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class Day10Test {
3434
@JvmStatic
3535
private fun getDataForTestSolvePart2(): Stream<Arguments> =
3636
Stream.of(
37-
Arguments.of("part2sample1.txt", 0L)
37+
Arguments.of("part2sample1.txt", 0L),
38+
Arguments.of("part2sample2.txt", 0L),
39+
Arguments.of("part2sample3.txt", 0L),
40+
Arguments.of("part2sample4.txt", 0L)
3841
)
3942
}
4043
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
...........
2+
.S-------7.
3+
.|F-----7|.
4+
.||.....||.
5+
.||.....||.
6+
.|L-7.F-J|.
7+
.|..|.|..|.
8+
.L--J.L--J.
9+
...........
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
..........
2+
.S------7.
3+
.|F----7|.
4+
.||....||.
5+
.||....||.
6+
.|L-7F-J|.
7+
.|II||II|.
8+
.L--JL--J.
9+
..........
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.F----7F7F7F7F-7....
2+
.|F--7||||||||FJ....
3+
.||.FJ||||||||L7....
4+
FJL7L7LJLJ||LJ.L-7..
5+
L--J.L7...LJS7F-7L7.
6+
....F-J..F7FJ|L7L7L7
7+
....L7.F7||L7|.L7L7|
8+
.....|FJLJ|FJ|F7|.LJ
9+
....FJL-7.||.||||...
10+
....L---J.LJ.LJLJ...
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FF7FSF7F7F7F7F7F---7
2+
L|LJ||||||||||||F--J
3+
FL-7LJLJ||||||LJL-77
4+
F--JF--7||LJLJ7F7FJ-
5+
L---JF-JLJ.||-FJLJJ7
6+
|F|F-JF---7F7-L7L|7|
7+
|FFJF7L7F-JF7|JL---7
8+
7-L-JL7||F7|L7F-7F7|
9+
L.L7LFJ|||||FJL7||LJ
10+
L7JLJL-JLJLJL--JLJ.L

0 commit comments

Comments
 (0)