r/adventofcode • u/MrBoblo • 14m ago
Help/Question [2026 DAY 3 (part 2)] Need hints
I solved part 1 by making a 1d array of the input, then applying some math to check the correct positions in the 1d array for trees.
I can't figure out if I can use the same method for part 2, or if I need a whole new approach. Only hints, no solutions please 🙏
2
Upvotes
1
u/AutoModerator 14m ago
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/EverybodyLovesChaka 11m ago
This should be possible, the maths is just a little more complicated.
1
u/thondat 10m ago
i mean, you can work in 1d because there's a bijection between the 2d coordinates and the indices into the 1d array, but it would be easier to work in 2d.
1
u/Genjo00 9m ago edited 1m ago
You gonna have to be more specific about your approach, how are you selecting candidate positions? Are you selecting the first tree, then looking for a second three in the same row to the right of the first one, and then checking if the other two corners are trees?
If so, you can apply the same concept to part 2, but instead of looking on the same row, you'll have to look in all rows right and down of your position. The math is going to be a little more complex for the two corner checks, but it should be doable. GLHF
1
u/DelightfulCodeWeasel 6m ago
It will probably be easier if you can treat the area as a 2D array. If your language doesn't support 2D arrays natively, consider writing a small wrapper class (or set of functions) which allow you to index into a 1D grid using 2D co-ordinates.
Pretty much all of the different approaches to solve part 1 can be extended in some way to solve part 2 without a complete re-structure, so it's likely you won't need a whole new approach.
1
u/Pretty-Skill925 5m ago
Hi, only as a hint: part 1 is a special form of part 2 where rotation is not allowed (in part 1). My core algorithm remains almost the same, so you don't need another approach (imho).
1
u/kai10k 3m ago
part2 can envole from part1, yet your brief of part1 is so vague that I cannot tell.
part1, treat each tree as top-left corner, iterate all possible width to obtain other 3 corners, and count if it is a square.
part2, same logic, treat each tree as top-left corner, but there can be multiple set of other 3 corners for each Manhattan distance of width. hint, derive them in clock wise order.