Skip to content

Commit 84c07b4

Browse files
committed
Added day05 part 1
1 parent a2e9b31 commit 84c07b4

File tree

6 files changed

+339
-2
lines changed

6 files changed

+339
-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.4.0'
7+
version '0.4.1'
88

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

day05/README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Day 5: If You Give A Seed A Fertilizer
2+
You take the boat and find the gardener right where you were told he would be: managing a giant "garden" that looks
3+
more to you like a farm.
4+
5+
"A water source? Island Island **is** the water source!" You point out that Snow Island isn't receiving any water.
6+
7+
"Oh, we had to stop the water because we **ran out of sand** to [filter](https://en.wikipedia.org/wiki/Sand_filter) it
8+
with! Can't make snow with dirty water. Don't worry, I'm sure we'll get more sand soon; we only turned off the water a
9+
few days... weeks... oh no." His face sinks into a look of horrified realization.
10+
11+
"I've been so busy making sure everyone here has food that I completely forgot to check why we stopped getting more
12+
sand! There's a ferry leaving soon that is headed over in that direction - it's much faster than your boat. Could you
13+
please go check it out?"
14+
15+
You barely have time to agree to this request when he brings up another. "While you wait for the ferry, maybe you can
16+
help us with our **food production problem**. The latest Island Island [Almanac](https://en.wikipedia.org/wiki/Almanac)
17+
just arrived and we're having trouble making sense of it."
18+
19+
The almanac (your puzzle input) lists all of the seeds that need to be planted. It also lists what type of soil to use
20+
with each kind of seed, what type of fertilizer to use with each kind of soil, what type of water to use with each kind
21+
of fertilizer, and so on. Every type of seed, soil, fertilizer and so on is identified with a number, but numbers are
22+
reused by each category - that is, soil 123 and fertilizer 123 aren't necessarily related to each other.
23+
24+
For example:
25+
```
26+
seeds: 79 14 55 13
27+
28+
seed-to-soil map:
29+
50 98 2
30+
52 50 48
31+
32+
soil-to-fertilizer map:
33+
0 15 37
34+
37 52 2
35+
39 0 15
36+
37+
fertilizer-to-water map:
38+
49 53 8
39+
0 11 42
40+
42 0 7
41+
57 7 4
42+
43+
water-to-light map:
44+
88 18 7
45+
18 25 70
46+
47+
light-to-temperature map:
48+
45 77 23
49+
81 45 19
50+
68 64 13
51+
52+
temperature-to-humidity map:
53+
0 69 1
54+
1 0 69
55+
56+
humidity-to-location map:
57+
60 56 37
58+
56 93 4
59+
```
60+
The almanac starts by listing which seeds need to be planted: seeds `79`, `14`, `55`, and `13`.
61+
62+
The rest of the almanac contains a list of **maps** which describe how to convert numbers from a **source category**
63+
into numbers in a **destination category**. That is, the section that starts with `seed-to-soil map:` describes how to
64+
convert a **seed number** (the source) to a **soil number** (the destination). This lets the gardener and his team
65+
know which soil to use with which seeds, which water to use with which fertilizer, and so on.
66+
67+
Rather than list every source number and its corresponding destination number one by one, the maps describe entire
68+
**ranges** of numbers that can be converted. Each line within a map contains three numbers: the **destination range
69+
start**, the **source range start**, and the **range length**.
70+
71+
Consider again the example `seed-to-soil map:`
72+
```
73+
50 98 2
74+
52 50 48
75+
```
76+
The first line has a **destination range start** of `50`, a **source range start** of `98`, and a **range length** of
77+
`2`. This line means that the source range starts at `98` and contains two values: `98` and `99`. The destination range
78+
is the same length, but it starts at `50`, so its two values are `50` and `51`. With this information, you know that
79+
seed number `98` corresponds to soil number `50` and that seed number `99` corresponds to soil number `51`.
80+
81+
The second line means that the source range starts at `50` and contains `48` values: `50`, `51`, ..., `96`, `97`. This
82+
corresponds to a destination range starting at `52` and also containing `48` values: `52`, `53`, ..., `98`, `99`. So,
83+
seed number `53` corresponds to soil number `55`.
84+
85+
Any source numbers that **aren't mapped** correspond to the **same** destination number. So, seed number `10`
86+
corresponds to soil number `10`.
87+
88+
So, the entire list of seed numbers and their corresponding soil numbers looks like this:
89+
```
90+
seed soil
91+
0 0
92+
1 1
93+
... ...
94+
48 48
95+
49 49
96+
50 52
97+
51 53
98+
... ...
99+
96 98
100+
97 99
101+
98 50
102+
99 51
103+
```
104+
With this map, you can look up the soil number required for each initial seed number:
105+
* Seed number `79` corresponds to soil number `81`.
106+
* Seed number `14` corresponds to soil number `14`.
107+
* Seed number `55` corresponds to soil number `57`.
108+
* Seed number `13` corresponds to soil number `13`.
109+
110+
The gardener and his team want to get started as soon as possible, so they'd like to know the closest location that
111+
needs a seed. Using these maps, find **the lowest location number that corresponds to any of the initial seeds**. To
112+
do this, you'll need to convert each seed number through other categories until you can find its corresponding
113+
**location number**. In this example, the corresponding types are:
114+
* Seed `79`, soil `81`, fertilizer `81`, water `81`, light `74`, temperature `78`, humidity `78`, **location `82`**.
115+
* Seed `14`, soil `14`, fertilizer `53`, water `49`, light `42`, temperature `42`, humidity `43`, **location `43`**.
116+
* Seed `55`, soil `57`, fertilizer `57`, water `53`, light `46`, temperature `82`, humidity `82`, **location `86`**.
117+
* Seed `13`, soil `13`, fertilizer `52`, water `41`, light `34`, temperature `34`, humidity `35`, **location `35`**.
118+
119+
So, the lowest location number in this example is **`35`**.
120+
121+
**What is the lowest location number that corresponds to any of the initial seed numbers**?

day05/src/main/resources/day05.txt

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
seeds: 629551616 310303897 265998072 58091853 3217788227 563748665 2286940694 820803307 1966060902 108698829 190045874 3206262 4045963015 223661537 1544688274 293696584 1038807941 31756878 1224711373 133647424
2+
3+
seed-to-soil map:
4+
3809825462 2725979505 339457863
5+
3359244708 2085610478 450580754
6+
652041572 2536191232 189788273
7+
841829845 3346349446 343599367
8+
1408035723 73701258 732851393
9+
2140887116 3689948813 88205018
10+
0 3778153831 371129494
11+
2953980724 0 73701258
12+
3027681982 1754047752 331562726
13+
2229092134 1029159162 724888590
14+
1185429212 806552651 222606511
15+
371129494 3065437368 280912078
16+
17+
soil-to-fertilizer map:
18+
201390752 0 263005475
19+
772560454 263005475 186665885
20+
3597849741 3228095269 216867970
21+
959226339 951560560 85171934
22+
2882237029 3813801625 34286208
23+
0 586356609 16090261
24+
1460387186 1189054013 136970257
25+
2511361703 2581174071 147006778
26+
201110502 1477157137 280250
27+
3582774663 3444963239 15075078
28+
2073881675 2245158204 30510333
29+
3127914126 3163440286 64654983
30+
1724767985 602446870 349113690
31+
1597357443 1036732494 127410542
32+
1044398273 1164143036 24910977
33+
635875205 449671360 136685249
34+
2916523237 2728180849 211390889
35+
1069309250 1854080268 391077936
36+
167223128 1820192894 33887374
37+
4168481019 2454687794 126486277
38+
3496254979 4048626015 86519684
39+
2454687794 4238293387 56673909
40+
2104392008 1648916365 171276529
41+
3814717711 3460038317 353763308
42+
464396227 1477437387 171478978
43+
2658368481 2939571738 223868548
44+
16090261 1326024270 151132867
45+
3393107291 4135145699 103147688
46+
3192569109 3848087833 200538182
47+
48+
fertilizer-to-water map:
49+
357701033 441924316 54941059
50+
2047098412 1574732688 106451110
51+
2414997091 2961420861 217583761
52+
3647103220 3202843177 147888878
53+
1781607871 3397471081 265490541
54+
433955285 629676938 29320532
55+
3280739425 2494455782 366363795
56+
2818710889 1426835569 147897119
57+
1120892574 3179004622 23838555
58+
1539573533 3662961622 195295312
59+
3794992098 1820059317 63264836
60+
0 84223283 357701033
61+
1144731129 1702496991 117562326
62+
2153549522 2046878176 261447569
63+
593734757 726830618 239035306
64+
987137385 83279657 943626
65+
2966608008 0 83279657
66+
1734868845 3350732055 46739026
67+
1438972249 2860819577 100601284
68+
2632580852 2308325745 186130037
69+
1262293455 965865924 108845646
70+
412642092 1681183798 21313193
71+
472462518 1305563330 121272239
72+
988081011 496865375 132811563
73+
463275817 2037691475 9186701
74+
3049887665 1074711570 230851760
75+
832770063 1883324153 154367322
76+
1371139101 658997470 67833148
77+
78+
water-to-light map:
79+
4062286509 3839153068 91029970
80+
1610728246 3827168971 11474903
81+
2753947407 2725849236 1101319735
82+
2525484879 1829977386 228462528
83+
657837215 1095779595 241604827
84+
1895347620 1337384422 492592964
85+
1425623249 4009599599 185104997
86+
2446068318 3930183038 79416561
87+
1894838426 3838643874 509194
88+
2389619503 896001044 56448815
89+
3855267142 2058439914 207019367
90+
1187459420 657837215 238163829
91+
1622203149 2467395620 172372577
92+
2387940584 952449859 1678919
93+
985523081 2265459281 201936339
94+
4153316479 954128778 141650817
95+
1794575726 4194704596 100262700
96+
899442042 2688664470 37184766
97+
936626808 2639768197 48896273
98+
99+
light-to-temperature map:
100+
0 2682471120 43545350
101+
2829609407 2423668531 227914183
102+
3685065657 3821208881 65673550
103+
1319277847 0 33132672
104+
818263707 3091863377 5216721
105+
3144636417 670795080 1340457
106+
1352410519 895535914 570572224
107+
2709351136 1662268878 120258271
108+
115643652 2726016470 93054822
109+
455333494 1538206440 124062438
110+
3839611769 4030334543 30664857
111+
3750739207 4258515305 36451991
112+
2070721515 33132672 155555065
113+
3132740473 2067641423 5192544
114+
4147162986 3685065657 58311172
115+
4278703737 3743376829 16263559
116+
1070098598 2174489282 249179249
117+
716608392 2072833967 101655315
118+
43545350 1466108138 72098302
119+
3057523590 3016646494 75216883
120+
2700979566 887164344 8371570
121+
4205474158 4060999400 73229579
122+
2226276580 188687737 474702986
123+
1971879519 1968799427 98841996
124+
3931845119 4134228979 124286326
125+
579395932 2819071292 137212460
126+
3137933017 672135537 6703400
127+
1062694241 663390723 7404357
128+
3787191198 3886882431 52420571
129+
269061216 1782527149 186272278
130+
1031805835 2651582714 30888406
131+
823480428 678838937 208325407
132+
3870276626 3759640388 61568493
133+
4056131445 3939303002 91031541
134+
1922982743 3097080098 48896776
135+
208698474 2956283752 60362742
136+
137+
temperature-to-humidity map:
138+
219529182 731674447 232727899
139+
2748076784 2771987989 46463882
140+
2514344851 4061235363 233731933
141+
0 1369964423 219529182
142+
452257081 362359049 21789881
143+
4243457964 2720478657 51509332
144+
3085663754 3109574959 64704581
145+
1639319644 384148930 347525517
146+
3150368335 3626166922 251414834
147+
1986845161 0 139120377
148+
1382707786 1339581093 30383330
149+
1413091116 1113352565 226228528
150+
2794540666 2818451871 291123088
151+
2125965538 338187591 24171458
152+
474046962 139120377 157229612
153+
2361125570 1100881680 12470885
154+
631276574 296349989 41837602
155+
3401783169 3428035243 198131679
156+
3989702261 3174279540 253755703
157+
2224646236 964402346 136479334
158+
2150136996 2299087215 74509240
159+
3806048654 3877581756 183653607
160+
3599914848 2514344851 206133806
161+
673114176 1589493605 709593610
162+
163+
humidity-to-location map:
164+
4029426902 1202474782 191291587
165+
2764446301 708692227 493782555
166+
2188304413 3350514524 33021460
167+
3318755823 4213528230 67155117
168+
2000392671 620732246 87959981
169+
3754724301 3075811923 274702601
170+
3258228856 1393766369 60526967
171+
2088352652 4113576469 99951761
172+
363515622 1849258760 614077493
173+
1213242541 342257124 11129119
174+
1733046668 353386243 267346003
175+
1224371660 4280683347 14283949
176+
2577070088 2888435710 187376213
177+
4220718489 2832149614 56286096
178+
324294413 1810037551 39221209
179+
3385910940 2463336253 368813361
180+
977593115 3383535984 235649426
181+
1238655609 3619185410 494391059
182+
4277004585 324294413 17962711
183+
2221325873 1454293336 355744215

day05/src/test/kotlin/de/havox_design/aoc2023/day05/Day05Test.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Day05Test {
2727
@JvmStatic
2828
private fun getDataForTestSolvePart1(): Stream<Arguments> =
2929
Stream.of(
30-
Arguments.of("part1sample1.txt", 0L)
30+
Arguments.of("part1sample.txt", 0L)
3131
)
3232

3333
@JvmStatic
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
seeds: 79 14 55 13
2+
3+
seed-to-soil map:
4+
50 98 2
5+
52 50 48
6+
7+
soil-to-fertilizer map:
8+
0 15 37
9+
37 52 2
10+
39 0 15
11+
12+
fertilizer-to-water map:
13+
49 53 8
14+
0 11 42
15+
42 0 7
16+
57 7 4
17+
18+
water-to-light map:
19+
88 18 7
20+
18 25 70
21+
22+
light-to-temperature map:
23+
45 77 23
24+
81 45 19
25+
68 64 13
26+
27+
temperature-to-humidity map:
28+
0 69 1
29+
1 0 69
30+
31+
humidity-to-location map:
32+
60 56 37
33+
56 93 4

day05/src/test/resources/part1sample1.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)