Day 10: Add explanation
This commit is contained in:
parent
56df7dcf85
commit
17321aa580
1 changed files with 29 additions and 0 deletions
|
@ -1,5 +1,34 @@
|
|||
# [Day 10: Adapter Array](https://adventofcode.com/2020/day/10)
|
||||
|
||||
## Part two explaination
|
||||
|
||||
If you take away all the extra details, all we're being asked to do in part two is to find the number of valid possible orderings of the list of joltages where a given ordering is valid if:
|
||||
|
||||
* it starts at zero and ends at 3 more than the highest input value
|
||||
* each value in the input is followed by a value that is between 1 and 3 more than itself
|
||||
* for example, if your value was `5`, it could be followed by `6`, `7`, or `8` only.
|
||||
* this also means that the value `5` can only be preceded by `2`, `3` or `4`.
|
||||
|
||||
We do not need to use all values from the input like we did in part one.
|
||||
|
||||
The number of valid combinations to reach value `n` is the sum of the number of valid combinations of `n-1`, `n-2` and `n-3`, assuming values are sorted in ascending order. If one of these numbers is not present in the input, it can be treated as zero.
|
||||
|
||||
Where `n` is `0`, there is only one way to combine a single number, hence it has a combinations value of 1.
|
||||
|
||||
For example, if we have the following data:
|
||||
|
||||
| n | Combinations |
|
||||
|---|---------------|
|
||||
| 0 | 1 |
|
||||
| 1 | 1 |
|
||||
| 2 | 2 |
|
||||
|
||||
We can find the number of valid combinations to get to the value `n=3` by doing `1 + 1 + 2 = 4`.
|
||||
|
||||
Using this method, we can find the answer to part two with a very small algorithm that's only 7 lines long, excluding data parsing.
|
||||
|
||||
---
|
||||
|
||||
<details><summary>Script output</summary>
|
||||
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue