Advent of Code 2024 - Day 2 - Red-Nosed Reports

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ธ.ค. 2024

ความคิดเห็น • 7

  • @publicacct5626
    @publicacct5626 2 วันที่ผ่านมา +1

    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.

  • @Larz99
    @Larz99 3 วันที่ผ่านมา +1

    I always enjoy your content. This is more fun that an Advent calendar, and lower calories too!

  • @germanwalks6226
    @germanwalks6226 19 ชั่วโมงที่ผ่านมา

    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.

  • @aaronperl
    @aaronperl 3 วันที่ผ่านมา

    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)

  • @NKCSS
    @NKCSS 2 วันที่ผ่านมา

    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 😁

    • @DanielPersson
      @DanielPersson  2 วันที่ผ่านมา +1

      It all depends on the channel. I allow links but I hold them for review. Don't want to spread spam to my viewers.

    • @NKCSS
      @NKCSS 2 วันที่ผ่านมา

      @@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