Day 5 Preparation

This commit is contained in:
Daniel Ziltener 2023-12-05 13:25:50 +01:00
parent de97d82354
commit 0244e00283
Signed by: zilti
GPG Key ID: B38976E82C9DAE42
1 changed files with 161 additions and 1 deletions

View File

@ -2248,7 +2248,7 @@ actually been printed on the back of every card this whole time.
There's no such thing as "points". Instead, scratchcards only cause you to *win more scratchcards*
equal to the number of winning numbers you have.
Specifically, you win copies of the scratchcards below the winning card equal to the number of
Specifically, you win *copies* of the scratchcards below the winning card equal to the number of
matches. So, if card 10 were to have 5 matching numbers, you would win one copy each of cards 11,
12, 13, 14, and 15.
@ -2362,6 +2362,8 @@ the original set of scratchcards, *how many total scratchcards do you end up wit
** Puzzle Input
Jump to [[#headline-48][day 5]].
#+NAME: day4-input
#+begin_src fundamental
Card 1: 33 56 23 64 92 86 94 7 59 13 | 86 92 64 43 10 70 16 55 79 33 56 8 7 25 82 14 31 96 94 13 99 29 69 75 23
@ -2571,3 +2573,161 @@ Card 204: 23 75 70 14 95 84 61 9 66 77 | 79 8 1 64 50 41 32 93 58 15 33 10 28
Card 205: 2 99 53 15 32 6 16 69 21 14 | 96 98 24 66 6 47 4 54 45 46 42 13 75 11 80 18 34 35 93 79 65 37 40 92 91
Card 206: 74 30 29 66 68 2 3 34 79 87 | 63 45 88 78 98 27 97 32 38 75 9 11 71 93 55 69 56 20 12 82 81 41 80 23 94
#+end_src
* Day 5: If You Give A Seed A Fertilizer
** Part One
*** Quest
You take the boat and find the gardener right where you were told he would be: managing a giant
"garden" that looks more to you like a farm.
"A water source? Island Island *is* the water source!" You point out that Snow Island isn't
receiving any water.
"Oh, we had to stop the water because we *ran out of sand* to [[https://en.wikipedia.org/wiki/Sand_filter][filter]] it 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 few
days... weeks... oh no." His face sinks into a look of horrified realization.
"I've been so busy making sure everyone here has food that I completely forgot to check why we
stopped getting more sand! There's a ferry leaving soon that is headed over in that direction - it's
much faster than your boat. Could you please go check it out?"
You barely have time to agree to this request when he brings up another. "While you wait for the
ferry, maybe you can help us with our *food production problem*. The latest Island Island [[https://en.wikipedia.org/wiki/Almanac][Almanac]]
just arrived and we're having trouble making sense of it."
The almanac (your puzzle input) lists all of the seeds that need to be planted. It also lists what
type of soil to use 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 of fertilizer, and so on. Every type of seed, soil,
fertilizer and so on is identified with a number, but numbers are reused by each category - that is,
soil =123= and fertilizer =123= aren't necessarily related to each other.
For example:
#+begin_example
seeds: 79 14 55 13
seed-to-soil map:
50 98 2
52 50 48
soil-to-fertilizer map:
0 15 37
37 52 2
39 0 15
fertilizer-to-water map:
49 53 8
0 11 42
42 0 7
57 7 4
water-to-light map:
88 18 7
18 25 70
light-to-temperature map:
45 77 23
81 45 19
68 64 13
temperature-to-humidity map:
0 69 1
1 0 69
humidity-to-location map:
60 56 37
56 93 4
#+end_example
The almanac starts by listing which seeds need to be planted: seeds =79=, =14=, =55=, and =13=.
The rest of the almanac contains a list of *maps* which describe how to convert numbers from a
*source category* into numbers in a *destination category*. That is, the section that starts with
~seed-to-soil map:~ describes how to convert a *seed number* (the source) to a *soil number* (the
destination). This lets the gardener and his team know which soil to use with which seeds, which
water to use with which fertilizer, and so on.
Rather than list every source number and its corresponding destination number one by one, the maps
describe entire *ranges* of numbers that can be converted. Each line within a map contains three
numbers: the *destination range start*, the *source range start*, and the *range length*.
Consider again the example ~seed-to-soil map~:
#+begin_example
50 98 2
52 50 48
#+end_example
The first line has a *destination range start* of =50=, a *source range start* of =98=, and a *range
length* of =2=. This line means that the source range starts at =98= and contains two values: =98=
and =99=. The destination range is the same length, but it starts at =50=, so its two values are
=50= and =51=. With this information, you know that seed number =98= corresponds to soil number =50=
and that seed number =99= corresponds to soil number =51=.
The second line means that the source range starts at =50= and contains =48= values: =50=, =51=,
..., =96=, =97=. This corresponds to a destination range starting at =52= and also containing =48=
values: =52=, =53=, ..., =98=, =99=. So, seed number =53= corresponds to soil number =55=.
Any source numbers that *aren't mapped* correspond to the *same* destination number. So, seed number
=10= corresponds to soil number =10=.
So, the entire list of seed numbers and their corresponding soil numbers looks like this:
#+begin_example
seed soil
0 0
1 1
... ...
48 48
49 49
50 52
51 53
... ...
96 98
97 99
98 50
99 51
#+end_example
With this map, you can look up the soil number required for each initial seed number:
- Seed number =79= corresponds to soil number =81=.
- Seed number =14= corresponds to soil number =14=.
- Seed number =55= corresponds to soil number =57=.
- Seed number =13= corresponds to soil number =13=.
The gardener and his team want to get started as soon as possible, so they'd like to know the
closest location that needs a seed. Using these maps, find *the lowest location number that
corresponds to any of the initial seeds*. To do this, you'll need to convert each seed number
through other categories until you can find its corresponding *location number*. In this example,
the corresponding types are:
- Seed =79=, soil =81=, fertilizer =81=, water =81=, light =74=, temperature =78=, humidity =78=,
*location =82=*.
- Seed =14=, soil =14=, fertilizer =53=, water =49=, light =42=, temperature =42=, humidity =43=,
*location =43=*.
- Seed =55=, soil =57=, fertilizer =57=, water =53=, light =46=, temperature =82=, humidity =82=,
*location =86=*.
- Seed =13=, soil =13=, fertilizer =52=, water =41=, light =34=, temperature =34=, humidity =35=,
*location =35=*.
So, the lowest location number in this example is *=35=*.
*What is the lowest location number that corresponds to any of the initial seed numbers?*
*** Puzzle Solution
#+begin_src scheme :exports none :noweb yes :tangle day5.scm
(import (chicken string)
(chicken irregex))
(define input "
<<day5-input>>
")
#+end_src
TBD...
** Part Two
** Puzzle Input