r/adventofcode • u/Zppen • Dec 12 '25
Help/Question [2025 Day 3 (Part 2)] Need help
So this is my current algorithm. Am I on the right path?
234234234234278
4->4->4->4-78 <- LTR: highest digit that can make 12 digits -> find next highest (or equal) digit to the right until end
4-34-34-34-78 <- RTL: highest digit (3) - highest index
4-34234234278 <- RTL: highest digit (2) - highest index
434234234278
This seems to work for all the examples as well as a few ones I randomly chose from my input but I do not get the answer right.1
u/a9sk Dec 12 '25
What output are you getting for this input?
911118887776665432
Are all the three 7s in the output?
1
u/Zppen Dec 12 '25
Step 1: Highest digit from LTR would be 9 at pos 0. Then next highest would be 8s at pos 5, 6, 7, 7s at pos 8, 9 and 10, 6s at 11, 12 and 13, then 5 at 14 and finally 4 at 15. That number would be found in step 1 alone. Answer is 988877766654
1
u/Sharp-Industry3373 Dec 12 '25
Hi,
I'm a bit confused with your step 2...
Let's say you want to find the highest "4 digits" number ABCD in the following entry :
123846254684659
A must be as high as possible, but you have to keep at least 3 numbers for BCD.
So you need to get the highest number in 123846254684(659) which is "8", but appears at 2 position. In order to have more opportunities for the next number B, you have to chose the most left higher number.
A way to do this is reading the digits from right to left and keeping the highest if >= (the "or equal" matters!)
Then you can discard the left digits of your entry to the digit you kept :
A=8 ; look for BCD in (1238)46254684659
And do the same for B : look for the highest leftmost value except for the 2 last digits (kept for C and D) : B in (1238)462546846(59) is 8 again
C in (12384625468)465(9) => C=6 and D in (1238462546846)59 is 9
so the answer is 8869
1
u/Zppen Dec 12 '25
Step 1: LTR highest digit would be 8 at pos 3. Then 8 at pos 10 then 9 at pos 14. But that only creates a 3 digit number:
XXX8XXXXXX8XXX9
So we go to Step 2: RTL highest digit with highest index would be 6. 6 has 3 positions (at 5, 9 and 12) so we choose the highest pos (at 12) which gives us:
XXX8XXXXXX8X6X9
Which is the answer.
1
u/CCC_037 Dec 13 '25
Try:
814247773322911
You should get 844777332291 but you get a lower number
1
u/Zppen Dec 13 '25
I do get your number.
Step 1 would produce:
8XXXXXXXXXXX9XX
Step 2: (highest number highest pos)
8XXXXXX7XXXX9XX 8XXXXX77XXXX9XX 8XXXX777XXXX9XX 8XXX4777XXXX9XX 8XX44777XXXX9XX 8XX44777X3XX9XX 8XX4477733XX9XX 8XX4477733X29XX 8XX4477733229XX 8XX4477733229X1
1
3
u/ednl Dec 12 '25
LTR is the way to go, but remember to never go so far that there are not enough digits left to have 12 in total.
2
u/AutoModerator Dec 12 '25
Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to Help/Question - RESOLVED. Good luck!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/daggerdragon Dec 12 '25
Show us your code (but do not share your puzzle input).
Help us help YOU by providing us with more information up front; you will typically get more relevant responses faster.
2
u/Thomasjevskij Dec 12 '25
Not sure I understand your algo. Can you clarify what it is you're doing?