menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Climbing a...
source image

Dev

1M

read

140

img
dot

Image Credit: Dev

Climbing a depth-first search hill, Advent of Code 2024, day 10

  • Today's Advent of Code 2024 Day 10 puzzle involves a 2D grid and multiple paths. Depth-first search is essential in solving this puzzle.
  • Every point on the map is a single-digit integer indicating its height, ranging from 0 to 9.
  • Each step along a trail must increase the height by exactly 1.
  • The functions 'parse' and 'find_trailheads' help in identifying trailheads and increasing the height by 1.
  • The algorithm starts at the root node and explores as far as possible along each branch before backtracking.
  • The climb function in this puzzle's case traverses by ascending one-height level at a time from a trailhead.
  • This depth-first search implementation returns all possible trails from each trailhead to the peak.
  • Part 1 requires us to find the total number of unique peak destinations reachable from all trailheads using the climb function.
  • Part 2 asks for the total number of unique trails between all trailhead-peak pairs, which is the sum of the number of trails for each key.
  • The code performs within a reasonable timeframe, reflecting valuable learning experience.

Read Full Article

like

8 Likes

For uninterrupted reading, download the app