kwando
Took a while, but another use case for “move vectors” today and pattern matching. ![]()
The trick was to first generate a list of position for the head with the help of the instructions.
Then you you use that list to move the tail, and repeat that process for as many knots there are.. a perfect job for Enum.scan ![]()
Quite happy with this solution.
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
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
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
(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
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #elixirconf-us
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #security
- #elixirconf-eu
- #api
- #forms
- #performance











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
adamu
You’re not supposed to share the problem text or input according to the AoC ToS. Although that’s probably a lost cause by now
Enjoyed this one. Part 2 took me by surprise, but it was fun. I managed to reuse the functions from part 1, just updated motion function to keep track of the intermediary knots in a list, with
map_reduceto simultaneously enumerate the knots + track the previous one.https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2022/day9.exs
adamu
@kwando That’s a nice use of Enum.scan. As you said, perfect for the task
Arzar
It was really fun coding this ̶s̶n̶a̶k̶e̶ rope-thing simulator (code below is part 2)
kwando
Oh, didnt know that. Gonna stop adding that to my livebooks
thanks for the heads up!
Joseph
This one was the most fun I’ve had in a long time
milli
After a lot of refactoring I’m solving both parts using the same function and I’m happy with my code
Full solution on GitHub
adamu
You are expanding out the directions, right? So if the head moves up 10k in one movement, you will have 10k up instructions in your list. And if another rope snaps and there are more knots, that’s a lot of work to traverse the whole rope to find the last one each time. Some points to consider if you want to spend more time refactoring
stevensonmt
I spent a lot of time refactoring my initial part 1 solution after reading the part 2 prompt and realizing I should be able to reuse the solution for both with the rope length as a parameter. Mostly had to change my data structure from
%{head: {x,y}, tail: {m,n}, visited: MapSet<>}to%{rope: [], visited: MapSet<>}. I’m still not pleased about reversing the list of knots on every move. Curious to see how others managed to avoid that.https://github.com/stevensonmt/advent_of_code/blob/2022/2022/day9/lib/day9.ex
LostKobrakai
This was actually more fun than I initially expected having read part 1 yesterday and opting to skip it till the weekend. I did need to refactor much for part 2. Just needed to replace reducing over
{0, 0}and a single move withList.duplicate({0, 0}, 9)and doing the move over the list as well.List.duplicatetogether withEnum.flat_mapalso turned out to be useful for the instruction list.Solution
milli
I forgot to mention I was refactoring mainly for beauty
It looks like we’ll get to enjoy enough of 10k optimizing in Day 11, though 