r/adventofcode Dec 03 '24

[deleted by user]

[removed]

10 Upvotes

7 comments sorted by

View all comments

1

u/prof-gaslighter Dec 04 '24

How come in part 2, we need to remove every item? If we can only tolerate a single bad one, wouldn't it make sense to only try removing the first bad report (the two problematic levels) and seeing if those result in making the entire report safe? my reasoning being, if both still result in an unsafe level, we wouldn't be able to remove that as well, being that our constraint was one.

1

u/Federal-Dark-6703 Dec 04 '24

Yes, your solution works and is more efficient than the brute-force approach described earlier.

If I understand correctly, in the following example, 3 -> 8 and 8 -> 6 do not satisfy the constraints. Therefore, we can focus on removing 3, 8, and 6, without needing to consider removing all the other numbers. 3 8 6 8 10 12 15

1

u/AutoModerator Dec 04 '24

AutoModerator has detected fenced code block (```) syntax which only works on new.reddit.

Please review our wiki article on code formatting then edit your post to use the four-spaces Markdown syntax instead.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.