I used the same approach. One small simplification you could consider for part B is removing the checkSafe() on line 61 and subsequent if(!safe) block. You can just jump straight into removing the first element and checking if that is safe.
instead of hit and trail method in the main function, I would try another approach to return the index of the item which caused the list to be unsafe from your check function, and then only remove that item from the list and check it again. I think that can also work.
I had trouble getting my brain in gear this morning .... my daughter was sick this weekend (stomach bug), on top of a whole bunch of other "life stuff" that has happened in the last couple of weeks (I took a mental health day off work on Friday), and I think I also had what she had but to a lesser degree. I had no trouble with Part 1, but was having a lot of trouble figuring out Part 2. Your comment about creating an "isValid" function was the tip I needed to go back and solve Part 2. I feel like there should be a cleaner way to do it rather than brute-force remove each element, but it does work in a fast enough time with the test input, so good enough for AoC :) To check for "all increasing or all decreasing", I am checking whether the sorted list is the same as the original list: report.sorted() == report || report.sortedDescending() == report ... which, of course, is only practical because the lists are very short... Otherwise I think my solution ended up being pretty similar to yours (especially after the hint)
Pretty sure I can't share links in YT comments, but I have my code linked in today's stream ☺ I was especially pleased with part 2 as I figured out the minimal checks that needs to be done 😁
I used the same approach. One small simplification you could consider for part B is removing the checkSafe() on line 61 and subsequent if(!safe) block. You can just jump straight into removing the first element and checking if that is safe.
I always enjoy your content. This is more fun that an Advent calendar, and lower calories too!
instead of hit and trail method in the main function, I would try another approach to return the index of the item which caused the list to be unsafe from your check function, and then only remove that item from the list and check it again. I think that can also work.
I had trouble getting my brain in gear this morning .... my daughter was sick this weekend (stomach bug), on top of a whole bunch of other "life stuff" that has happened in the last couple of weeks (I took a mental health day off work on Friday), and I think I also had what she had but to a lesser degree. I had no trouble with Part 1, but was having a lot of trouble figuring out Part 2. Your comment about creating an "isValid" function was the tip I needed to go back and solve Part 2. I feel like there should be a cleaner way to do it rather than brute-force remove each element, but it does work in a fast enough time with the test input, so good enough for AoC :)
To check for "all increasing or all decreasing", I am checking whether the sorted list is the same as the original list:
report.sorted() == report || report.sortedDescending() == report
... which, of course, is only practical because the lists are very short...
Otherwise I think my solution ended up being pretty similar to yours (especially after the hint)
Pretty sure I can't share links in YT comments, but I have my code linked in today's stream ☺ I was especially pleased with part 2 as I figured out the minimal checks that needs to be done 😁
It all depends on the channel. I allow links but I hold them for review. Don't want to spread spam to my viewers.
@@DanielPersson Ah, ok, I just assumed TH-cam filters them all out anyways 😅 I'll post the link in a bit, let me grab it