mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-12-22 16:16:26 +00:00
27 lines
1.8 KiB
Markdown
27 lines
1.8 KiB
Markdown
# Day 2
|
||
|
||
In part two i got stuck because I wanted to be smart. Don't be smart, unless you really are, unlike me.
|
||
|
||
So [the challenge](https://adventofcode.com/2024/day/2) was to allow one possible error in a _report_
|
||
|
||
Given the level `1 3 2 4 5`, which fails because the 2 decreases, instead of increasing, i though it would be neat to only try removing one of each numbers.
|
||
In this case either the `3` or the `2`. I did not want to brute force through the array. What was i missing?
|
||
|
||
I then quickly found out, as the brute force variant is trivial to implement (on error, just retry every combination with one missing, breaking at the first _safe_ combination). The output was correct with the brute force variant, but my "smart™️" solution was off by very little, so what were the few edge cases?
|
||
|
||
These 4 are safe with the _Problem Dampener_, but were not detected by my "smart™️" algorithm.
|
||
|
||
```
|
||
[55, 52, 53, 54, 56, 57]
|
||
[17, 15, 16, 19, 20, 23, 25]
|
||
[56, 57, 56, 55, 54, 51, 50, 49]
|
||
[81, 84, 81, 80, 77, 75, 72, 69]
|
||
```
|
||
|
||
Why? well the issue was, that the error always occurred when the wrong number was the first one, giving a bad prediction for the "direction", basically whether the numbers would increase or decrease. Since the issue was always the third number with index `2`, removing either the second or third element was not enough, as the root cause was that the first items was already wrong, but only detected to late.
|
||
|
||
## Possible solutions
|
||
|
||
In my head, another way to visualise it, was to think in differences, where the first element would be always 0, and the next ones the diff to the previous one. In that case we could check for steady increase/decrease by making sure that all the subsequent numbers are all positive or negative.
|
||
Basically like a drawn line, with one outlier.
|