They’re regular springs now, because they’re not so hot -a characteristic that is quite important for hot springs-.
It’s because the lava stopped flowing, you should go take a look why.
You should be able to find a spring that is springy enough to launch you up to the place lava comes from here.
But they have fallen into disrepair, many of them are damaged.
You get a map of the hotsprings condition, per hotspring it lists if it is;
# damaged
. operational
The map itself is also damaged, causing a bunch of hot springs to have an unknown condition:
? unknown
Luckily, the elf with you helps you with a different format that lists the size of contiguous groups of damaged springs for every line.
This list always accounts for every damaged spring.
Each number is the entire size of its contiguous group (that is, groups are always separated by at least one operational spring: #### would always be 4, never 2,2).
An example of an undamaged input would look like this:
An example of the real, damaged input looks like this:
Parsing
I represented every record as a struct with a list of springs and a list of counts:
I represented each spring as an enum variant:
The parsing function returns a list of Records:
Part 1
It is your job to figure out how many different arrangements of operational and broken springs fit the given criteria in each row.
The question asks for the sum of valid arrangements for each line in your input.
some skeleton/pseudo-code:
Helpers
To check the amount of valid arrangements for a record, I used recursion.
If the argument to the function (a record) has an unknown spring in its list of springs, I replace it:
As a damaged spring
As an operational spring
For those 2 options, I calculate the amount of valid arrangements and sum them.
If the argument to the function (a record) has NO unknown springs in its list of springs, I check its validity.
If it’s valid, it has 1 valid arrangement (because there are no unknown springs left), if it’s invalid, it has 0.
This helper checks if an arrangement of springs (one with no unknown springs in it) is valid by calculating the list of counts that arrangement would have.
If the calculated counts match the given counts completely, it was a valid arrangement.
Putting it all together, the pseudocode works perfectly.
To unfold the records, on each row, replace the list of spring conditions with five copies of itself (separated by ?) and replace the list of contiguous groups of damaged springs with five copies of itself (separated by ,).
So, this row:
.# 1
Would become:
.#?.#?.#?.#?.# 1,1,1,1,1
The first line of the above example would become:
???.###????.###????.###????.###????.### 1,1,3,1,1,3,1,1,3,1,1,3,1,1,3
This makes the runtime of the code above too large to complete in a reasonable time.
I tried doing what’s called a pro gamer move and throw some memoization on it,
but alas,
I couldn’t get it to work before I had to do other stuff.