Bill Wallis’ Post

Here's my DuckDB solution to Advent of Code day 10, Hoof It The solution I’ve used for parts 1 and 2 are identical, other than counting the score in the final SELECT statement 😋 Start with the usual exploding of the data into a row per point on the map, and add a helper table for the surrounding points Next, walk through the map using a recursive CTE The cross join on the helper table adds a step in the potential route for each direction, then the inner join only keeps the ones that are one height above Keeping track of the initial X, Y coordinates (the “trailhead”) enabled us to group by it in the solution: • For part 1, just count the distinct final positions for each trailhead, then sum them • For part 2, just count the total number of routes for each trailhead, then sum them How did you solve the day 10 problem? #sqlwithbill #sql

  • No alternative text description for this image
  • No alternative text description for this image
  • No alternative text description for this image
  • No alternative text description for this image
  • No alternative text description for this image

📌 I'll be sharing my DuckDB solutions as I go -- find the full list in the comments of the post below, or check out the #sqlwithbill hashtag to see all my recent posts https://www.linkedin.com/posts/bill-wallis_sqlwithbill-sql-activity-7270430895344336897-0Nuu The full SQL is available here: https://github.com/Bilbottom/advent-of-code/tree/main/advent_of_code/solutions/year_2024/day_10

Like
Reply

To view or add a comment, sign in

Explore topics