Advent of Code 2024 Day 6

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ม.ค. 2025

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

  • @tgd2096
    @tgd2096 หลายเดือนก่อน +9

    Hey Neil, great to see your videos again this year (and nice to have them same day). For part 2, perhaps you just check what happens when you place objects in the “seen” spaces rather than the whole grid? 😀

    • @nthistlethwaite
      @nthistlethwaite  หลายเดือนก่อน

      Yep, it sounds like this is the big easy optimization - it brings my PyPy solution down to 5 seconds or so once I do this.

    • @shamilcarela1699
      @shamilcarela1699 13 วันที่ผ่านมา

      Awesome advice!

  • @harisimer
    @harisimer หลายเดือนก่อน +6

    you discovering bugs has a very humoristic touch

    • @nthistlethwaite
      @nthistlethwaite  หลายเดือนก่อน

      Haha, glad you're enjoying it

  • @flob7983
    @flob7983 หลายเดือนก่อน

    A colleague of mine recommended me checking out your AoC videos and I must say this was really nice to watch. Thanks for uploading that. Will from now on also check out your other videos.

  • @QuotePilgrim
    @QuotePilgrim หลายเดือนก่อน +2

    The algorithm I wrote for part 2 only took 20 minutes to compute 😆
    Part of the reason why was that as you might have imagined I'm replacing every single dot with an obstacle and checking if that causes a loop, but what may be even worse is that I'm not storing the position of the guard at all - at every iteration I have to find where the guard is and then update the map accordingly.
    So the two obvious optimizations are: "just store the coordinates of the guard's current position you dingus", and instead of testing every single possible obstacle position, run the part 1 algorithm once while storing the position of where the guard is looking at after every step or turn, and then only replace those with obstacles.

    • @nthistlethwaite
      @nthistlethwaite  หลายเดือนก่อน

      Hey, I mean if it works it works! One of the things I love about Advent of Code is that you can get away with lots of different levels of optimization, so if it's net faster to write some slower code by skipping some optimization, then you can do it. And IMO this is a very real-world tradeoff, because developer/researcher time is expensive! Obviously there's a limit to this and in the real-world you need to think about the actual costs of your slow code, but still this isn't something you get in more traditional competitive programming contests.
      Although, 20 minutes is a pretty long time, so writing the first optimization at least does sound pretty helpful :P

  • @gupta_samarth
    @gupta_samarth หลายเดือนก่อน +3

    For part 2, since it's essentially a functional graph, addition of an obstacle updates upto 4 of the outgoing edges, and you can quickly compute the jumps to just before an updated node, similar to CSES Planet Queries. Overall O(N*M)

  • @jagpreetjakhar7560
    @jagpreetjakhar7560 หลายเดือนก่อน +2

    I think you just need to check for points in the path in first part , so list(seen) and remove start, then its much faster

    • @nthistlethwaite
      @nthistlethwaite  หลายเดือนก่อน

      Nice, yeah, this is a pretty big improvement.

  • @God-i2
    @God-i2 หลายเดือนก่อน +3

    This year GPT users have ruined it for everybody.

    • @nthistlethwaite
      @nthistlethwaite  หลายเดือนก่อน +1

      Well, technically just ruined it for people competing for leaderboard, but yeah it is kinda sad. Obviously you're always going to get some people who don't care about respecting Eric's wishes and not leaderboarding with LLMs, but it's surprising to me how many of these people there are this year, and that they include relatively well-known people like geohot.

  • @curiousmushroom9900
    @curiousmushroom9900 หลายเดือนก่อน +2

    Hey neil !
    Do you know Julia ? It could be useful in those pypy situations, where you'd want interpreted syntax but "compiled performance"

    • @nthistlethwaite
      @nthistlethwaite  หลายเดือนก่อน

      I don't, but that's a neat idea! I think changing languages on the fly might be a bit too slow competitively for me, and PyPy already exists, but there definitely are good reasons to use other languages for these problems.

  • @guillermojanner5369
    @guillermojanner5369 หลายเดือนก่อน +1

    Nice videos, impressive to see your speed. Were you just luck that in your input the direction is downwards as you chose cd = 0 ? If your starting position would be not looking towards (-1,0) your solution would have been wrong? Did you check what was the starting direction in the input visually?

    • @nthistlethwaite
      @nthistlethwaite  หลายเดือนก่อน

      Thanks! I did visually check what it was, that was why I initially wrote the check as "^>

  • @BiopticPine
    @BiopticPine หลายเดือนก่อน

    How did I get a different answer for part 2? Do we get different inputs?

    • @nthistlethwaite
      @nthistlethwaite  หลายเดือนก่อน

      Yep, everyone gets their own unique input.

  • @adwaithsudheer877
    @adwaithsudheer877 หลายเดือนก่อน

    hy can you give code for part 2 am not able to complete

    • @nthistlethwaite
      @nthistlethwaite  หลายเดือนก่อน

      If you really want it, I do usually post my code on the subreddit megathreads (here's a day 6 link: www.reddit.com/r/adventofcode/comments/1h7tovg/comment/m0nyj8k/?), although
      - the code I post is pretty messy and isn't always fully general
      - it also needs my helper library in the same directory to run (gist.github.com/nthistle/5244b04be6a2eae545e6908369d39592)
      - you don't learn anything if you just use someone else's code! I'd really encourage you to try to solve yourself, even if it just means re-writing your own code after seeing the general approach somewhere else