DEV Community

Cover image for Advent of Code '24 - Day 10: Hoof It
Grant Riordan
Grant Riordan

Posted on • Edited on

2

Advent of Code '24 - Day 10: Hoof It

Advent of Code Day 10: Hoof It

Link to Solution

This one (like many other it seems) managed to inadvertently solve Part 2 whilst doing Part 1, or at least Part 2 required very little extra effort.

Summary of Problem & Solution

I think where many of us devs went wrong today as we didn't fully understand the requirement of :

A trailhead's score is the number of 9-height positions reachable from that trailhead via a hiking trail.

But this could be misinterpreted as all the 9's from that trailhead not unique. However, alas it should be unique 9's, but it made for an easy solution to Part 2 (which is why many many quick Part2 solution times haha)

Part 1: Unique Paths to 9

The goal is to count how many unique 9 positions can be reached from each trailhead (0). This involves:

Finding all reachable 9 positions from each trailhead.
Using a HashSet of visited 9 positions (visitedEndPoints) to ensure uniqueness.

For each trailhead:
Traverse valid paths using the BFS (Breadth First Search) algorithm.

Keep track of all 9 positions reached from that trailhead (unique).

Finally:
Sum up the counts of unique 9 positions reachable from all trailheads.
This forms the "score" of each trailhead.

Part 2: Count All Distinct Paths

Here, the focus shifts to counting the number hiking trails from each trailhead. This involves:

Counting all possible paths (not just unique endpoints).

Problem Solved - As always feel free to give me a follow on Twitter where you can be notified of my articles on DevTo, FreeCodeCamp and other dev tips and tricks.

Billboard image

Monitoring as code

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay