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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










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.