seeplusplus
This one wasn’t too bad
I actually ended up solving part 2 first, and had to work around it in part 1 to get the answer there!
input = ""
|> String.trim()
tiles = input |> String.split("\n")
|> Stream.with_index()
|> Enum.flat_map(fn {line, l_idx} ->
line
|> String.trim()
|> String.graphemes()
|> Stream.with_index()
|> Enum.map(fn {".", idx} -> {{idx, l_idx}, nil}
{c, idx} -> {{idx, l_idx}, c |> String.to_integer()} end)
end)
|> Enum.into(Map.new())
grid = Grid2D.new(
input |> String.split("\n") |> Enum.at(0) |> String.trim() |> String.length(),
input |> String.trim() |> String.split("\n") |> Enum.count()
)
defmodule TrailFinder do
def find_trails(input, tiles, grid) do
tiles
|> Stream.filter(fn {_, v} -> v == 0 end)
|> Enum.map(fn {k, _} -> {k, find_trails(input, tiles, grid, k, 0, [])} end)
end
def find_trails(_, _, _, p, 9, acc), do: [[{p, 9} | acc]]
def find_trails(input, tiles, grid, start, height, acc) do
Grid2D.neighbors(start, grid, :straight)
|> Enum.filter(fn p -> Map.get(tiles, p) == height + 1 end)
|> Enum.flat_map(fn p ->
find_trails(input, tiles, grid, p, height + 1, [{start, height} | acc])
end)
end
end
TrailFinder.find_trails(input, tiles, grid)
|> Enum.map(fn {s, l} -> {s, for [peak |_] <- l, into: MapSet.new do peak end } end)
|> Enum.map(fn {_, s} -> MapSet.size(s) end)
|> Enum.sum()
TrailFinder.find_trails(input, tiles, grid)
|> Stream.map(fn {_, l} -> l |> Enum.count end)
|> Enum.sum()
Trending in Challenges
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
rugyoga
Same!
I accidentally solved part 2 first and then fixed it to run part1. lol
https://github.com/rugyoga/aoc2023/blob/main/lib/2024/10.ex
Aetherus
Solved Part 2 first, too. Here’s my code using dynamic programming (not very FP, though):
Benchmark (without the parsing part)
bjorng
And I also solved part 2 first.
https://github.com/bjorng/advent-of-code/blob/main/2024/day10/lib/day10.ex
sevenseacat
Is this the first time I’ve cranked out the graphs for 2024? I think it is…
https://github.com/sevenseacat/advent_of_code/blob/main/lib/y2024/day10.ex
Part 2 was trivial after implementing part 1. I like when that happens.
adamu
Solving part2 first club++.
I guess the functional language forces us to think recursively, although I found it quite hard to reason about Part 1, it turned out I just needed to add a
uniqcall to the part 2 solution.https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2024/day10.exs
lud
My solution uses my grid module with BFS search, so it’s not very interesting to share so just the link
Aetherus
Less interesting solution (no brainer):
https://github.com/Aetherus/advent-of-code/blob/0cd3b4686a6cdb4aac1e91ca8dc5742ff0dc6a78/2024/day-10-graph.livemd
rySeeR
After having the most inefficient code yesterday that took almost 40 minutes to run hahaha, I’m surprised that today tooks 2ms to run, at the first try.
Also solved both at the same time.
I think it might be time to build a custom grid module…
https://github.com/jbonet/advent_of_code_2024/blob/main/lib/advent_of_code_2024/days/10.ex
billylanchantin
LOC: 21
I can’t figure out how to build grids on 1 line without
import Enum, so grids always take at least 2 lines.Flo0807
My solution. I tried something different and represented the grid by a single list today.