Skip to content

Latest commit

 

History

History

day10

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Puzzle 01

I used recursion to hike from trailheads and collect the coordinates of 9s that I could reach. I used #uniq to get a score as "how many 9s I can reach from this trailhead."

Puzzle 02

By removing the call to #uniq, the #hike method returned one coordinate for each path. Counting the paths gave me the rating I was looking for.

JavaScript

I tried to port this solution to JavaScript. For fun. The hard part was replicating Ruby's Array#uniq. I used simple tuples for coordinates, and a JavaScript Set didn't de-dupe them because it used object identity to find duplicates. In the end, I converted coordinates to JSON strings before de-duping, and that did the trick.