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
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
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
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
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)
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 