r/adventofcode • u/MichalMarsalek • Dec 10 '20
Help - SOLVED! [2020 Day 10 (part 2)] Suspicious factorisation
I noticed that my answer was 2^6 × 7^14. It probably has an easy explanation, but I guess I'm still a bit sleepy....
All solutions I've seen use DP using summing but if there's a pattern, then we could exploit it and directly figure out the exponents in the prime factorisation, right?
EDIT:This works because:
- There's no gap of 2.
- The longest consecutive run is 5.
This means, that to get from one group of consecutive numbers to the next one you need to make a 3 jump, that is you need to jump between the edge numbers.
That is the solution is determined by how many ways you can get from the lowest number in a group to the highest in each of the groups.
This number of ways to traverse a group is only determined by its size and for sizes <= 5 its of the form 2^a × 7^b. The overall solution is just a product of the partial ones.
7
u/LieutenantSwr2d2 Dec 10 '20 edited Dec 10 '20
I found a relation between the number of consecutive 1 voltage differences to the Tribonacci sequence and was able to get a solution doing simple multiplication.
Edit:
To expand further, if you have a chain of consecutive adapters (e.g. 14, 15, 16, 17), you can use the length of the chain to figure out the multiplier. In the case of [14, 15, 16, 17], you multiply by 4.
The multiplier is the Tribonacci sequence:
Edit2:
As some replies have mentioned. Yes, this only works with the pre-condition that the gaps are only of size 1 and 3. I dumped the gaps during part 1 and saw that there are none of size 2, which is why I went for this approach.
7
u/Zefick Dec 10 '20
But they could be. Then any cornercutting solution that relies on their inexistence will not work, right? For example, if you remove 11 from the first example then the right answer becomes 4.
4
u/phrodide Dec 10 '20
Not knowing DP, I solved it with powers just like you said. I was shocked to see nobody else used powers.
Now I need to learn DP.
2
u/A_Non_Japanese_Waifu Dec 10 '20
Tribonnacci sequence. While an outlet of difference 2 exists, there will always be an outlet inbetween.
See the following:
[[0, 1, 2, 3, 4], [7], [10], [13], [16], [19, 20, 21], [24], [27, 28, 29, 30, 31], [34], [37, 38, 39, 40, 41], [44, 45, 46, 47, 48], [51], [54], [57, 58, 59, 60, 61], [64], [67, 68, 69, 70], [73, 74, 75, 76, 77], [80], [83, 84], [87], [90, 91, 92, 93, 94], [97], [100, 101, 102, 103, 104], [107, 108, 109, 110, 111], [114, 115, 116, 117, 118], [121, 122, 123], [126, 127, 128, 129], [132], [135, 136, 137, 138, 139], [142], [145, 146, 147], [150, 151, 152], [155, 156, 157], [160, 161, 162, 163, 164]]
I splitted the input into arrays that have a difference of 3, and notice that, in each small array, all indexes are continuous numbers. This is where I see the Tribonnacci hint.
Not recommended if you want to really be good at coding.
23
u/Slinger17 Dec 10 '20 edited Dec 10 '20
Simple math explanation:
Any two numbers that are separated by 3 must be in every single possible sequence. If you remove even one of those numbers, your gap is too large to bridge and you have an invalid sequence.
All other numbers tho are now optional and any combination of those numbers included or excluded is valid. For example, in a list if [0,1,2,3,6], we can see [0,3,6] are all essential numbers. [1,2] are optional. That leaves 4 possible combos of valid lists:
We have 4 possible combinations, or 22
What happens with the list [0,1,2,3,4,7] though? Well, [0,4,7] are essential, and [1,2,3] are optional. However, if we list out all possible combos of [1,2,3], you'll notice 1 combo is invalid: the combo where all of them are excluded. That would leave too large of a gap between 0 and 4, so we need at least one of those numbers
That means our total valid combos are 23 - 1, or 7
Your input is just combinations of the above two scenarios (or a final one where there is exactly 1 number between essential numbers, meaning 2 combos).
Multiply them all up to get your answer, which will be in the form 2m * 7n
1
u/MichalMarsalek Dec 10 '20
Thank you everyone for your answers. :) I could have figured this out on my own but perhpas this post can be of interest to someone else too.
4
u/MmmVomit Dec 10 '20
It looks like all the adapters are spaced either 1 or 3 jolts apart. The only parts of the sequence where the paths start to multiply is where you have multiple adapters that are 1 jolt apart. A sequence of three 1 jolt gaps multiplies the number of paths by 2. A sequence of four 1 jolt gaps multiplies the number of paths by 4. A sequence of five 1 jolt gaps multiplies the number of paths by 7.
So, prime factors of 2 and 7 just means you didn't have a sequence of 1 jolt gaps of longer than 5. If there were 2 jolt gaps anywhere, you'd be able to have more complex prime factors.
1
u/TinBryn Dec 10 '20
Thinking about it a bit more, it's not that strange. also I got 217 × 79, I wonder if you can work it out by using the 1jolt, 2jolt and 3jolt increment counts from part 1
1
u/corqscrew Dec 10 '20
Interesting, my solution ended up being 2^14*7^10, it's definitely not obvious to me why those are the only prime factors or if it's just coincidence.
1
u/BradleySigma Dec 10 '20 edited Dec 10 '20
Here's a Python solution that uses this pattern:
1
u/Fine_Tie Dec 10 '20
Actually for let say n consecutive 1 the number of combination it will be n(n-1)/2 + 1. So let say n1, n2, n3, ..., np are how many 1 are consecutive the total number of combinations it will be (n1(n1-1)/2 + 1)(n2(n2-1)/2+1)...(np(np-1)/2+1).
1
u/Supermathie Dec 10 '20
This is how I solved it as well.
1
u/_AngelOnFira_ Dec 10 '20
Don't know if this is of interest, but one of my wrong answers for pt2 was the right answer for someone else's solution. Very odd that we collided. Don't remember what I did to mess up though.
1
u/motherjoe Dec 11 '20
The number of configurations for each sequence of 1's seems to work with the Lazy Caterer's sequence. Solution
1
u/WhaleAxolotl Dec 13 '20
Thanks, would not have solved this one without this.
1
u/PeaTearGriphon Dec 30 '20
ugh, never heard of Tribonacci sequence. I'm still not sure I'm getting this. I knew that any gap smaller than 3 was going to be where numbers could be removed but going from the most numbers to the least was going to take some serious weird code that I couldn't wrap my head around. Now it seems you can calculate the answer by counting the chains of 1-jolt gaps and multiplying those?
I don't understand the 2m X 7n Formula. What does the 2 and 7 represent? and what do you put in for m and n?
I read through the code someone posted to try and get a better understanding and it appears you keep a running total for power of 7 and power of 2 (POW7, POW2), every time a gap of 3 appears they subtract 2 from POW2 and add 1 to POW7, if the gap is 1 then they add 1 to POW2.
It sort of makes sense except for the 7 portion. I get that gaps of 1, especially consecutive, add many arrangements. The gap of 3 should add no arrangements but I'm not sure why it would remove arrangements or what the 7 portion does.
I should mention I only program business apps so this is way out of my debt.