Advent of Code 2024 | Day 10 "Hoof It"

Поділитися
Вставка
  • Опубліковано 26 січ 2025

КОМЕНТАРІ • 29

  • @satyaanshu
    @satyaanshu Місяць тому +19

    Today was interesting. I inadvertently solved for Part2 first, before realising my bug and subsequently fixing it for Part1 and then undoing my changes to get Part2 answer 😂

  • @yajusgakhar6969
    @yajusgakhar6969 Місяць тому +6

    I have reached a point where with every problem I try, I also have to solve the "WHAT AM I DOING WRONG???" part

  • @anw_g01
    @anw_g01 Місяць тому

    Not sure if recursion was a valid choice for this problem but I attempted it and was only able to finish it after looking at your BFS and understanding th. The conditions are actually identical but with slightly different added logic (like a base case) due to call stack stuff etc. Code provided below if anyone is interested. Not sure if this algorithm has an actual name, possibly DFS? (apologies, not a CompSci student)
    def traverse(grid, r, c, visited: set):
    if grid[r][c] == 9: # base case: summit found (trail completed)
    return 1
    dir = [(-1, 0), (0, 1), (1, 0), (0, -1)] # directions to check trails
    summits = 0 # count variable to accumulate

    for dr, dc in dir:
    nr, nc = r + dr, c + dc # new location (in direction)
    if not (0

  • @orion1312
    @orion1312 Місяць тому

    solution for part 1 involved grabbing all different summits you could get from any start (by filtering the ones seen already)... and then part 2 was just printing the whole thing without filtering.
    I actually took a longer time playing around with directionals and structures than solving the thing (I'm playing around with C only primitives and no fancy library functions other than my own), its really funny to see pythonland from that angle
    Great videos as always!

  • @hyperbolia-44031
    @hyperbolia-44031 Місяць тому +4

    My solution was interesting: I just did a BFS like you but stored a set of 9s reached for part 1 and returned the length of that set, then for part 2 returned the length of a list (not a set) of nines for a simple modification

    • @hyperbolia-44031
      @hyperbolia-44031 Місяць тому

      Since each path taken is different, it will guarantee that each way a 9 can be reached is counted exactly once

    • @hyperbolia-44031
      @hyperbolia-44031 Місяць тому

      Pretty much like your alternate solution

    • @griffinbaker860
      @griffinbaker860 Місяць тому

      did the same, but with DFS

    • @hyper-neutrino
      @hyper-neutrino  Місяць тому +1

      yep, that's how i did it during my initial solve at midnight as well, but instead of changing the set to a list i just changed it to a counter

  • @Zamai
    @Zamai 28 днів тому

    my answer for part 1 and 2 were exactly as yours "737", "1619" maybe we got the same seed :D
    wondering how many unique seeds there are for each task

  • @TheFrogfather1
    @TheFrogfather1 Місяць тому

    Got part 1 (with help from your video - thank you!) but part 2 will need to wait until after the day job.

  • @craigers0521
    @craigers0521 Місяць тому

    haha for my solution on part 2 i just commented out the one condition where i was checking if the position was already in seen or not and it worked. Maybe i got lucky.
    edit: just finished watching and yeah thats the same thing you did in contest

  • @pmareke
    @pmareke Місяць тому

    Nice solution!!! I use recursion instead. Why do you prefer BFS (just curiosity)?

    • @Cwiet
      @Cwiet Місяць тому

      Because it shouts for BFS or DFS?

    • @hyper-neutrino
      @hyper-neutrino  Місяць тому +2

      with BFS i don't need to worry about blowing up the stack and BFS finds the shortest path. DFS doesn't really work unless you have a sufficiently small acyclic graph; this applies here but it's easier to not have to think about the structure lol

    • @terryaney73
      @terryaney73 Місяць тому

      @@hyper-neutrino For some reason, I don't think you have a problem with 'thinking'. Great video as always.

  • @MegaSydman
    @MegaSydman Місяць тому +1

    I was wondering why everyone uses deque insted of list with pop(0). Then i read the python docs:
    Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.
    Today performance wasnt an issue, so you could shave a few seconds by using a list instead 😅

    • @hyper-neutrino
      @hyper-neutrino  Місяць тому +1

      hmm, that's true. maybe today would've been a good opportunity to show off a trick for replacing a queue with a list; rather than using pop(0) you can sacrifice a bit of memory for speed by just looping through the list. you can append to a list as you loop through it so you can just do "for cr, cc in q" and then append to "q" within the loop

    • @MegaSydman
      @MegaSydman Місяць тому

      @hyper-neutrino cool, didn't know you could alter the list you are looping!

  • @pandrr2355
    @pandrr2355 Місяць тому

    goat