Qqwy
TypeCheck Core Team
Note by the Moderators: This topic is to talk about Day 6 of the Advent of Code.
For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
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
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #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
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #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)
ryanwinchester
Anybody do this yet?
I can’t even figure out how they want me to build the areas. The description just leaves me like…
NobbZ
A certain square belongs to point X, if there is no other point Y that is closer than X using Manhattan distance.
sasajuric
I struggled with this one more than I’m willing to admit, and ultimately made a brute-force solution which works reasonably fast and is not very ugly. You can find it here.
kwando
Today was a bit tricky.. I scraped my elixir solution and wrote one in javascript (which would be trivial to translate to Elixir now when I know how).
Part 1.
I implemented a “flood fill” algorithm, relying on the fact that it is easy to enumerate all positions with distance N from a given position.
Part 2.
Step 1. Find the center of gravity
Step 2. ´Enumerate all positions with distance N from the center, count positions where the condition is true (sum all manhattan distances to the position). Continue to do this with distance N + 1, stop when the conditions fails for all positions in a level (N).
NobbZ
Finally I found the time to sit down and do day 6.
I’m not very happy with the code, as it is brute force.
Part 1 checks every square in a given bounding box for the nearest coordinate from the input, and returns a list of tuples, where the first element is the input coordinate and the second the actual field. Then I group by the input coordinate and reject those that are infinite (an area is classified as infinite if the line to the “owner” is orthogonal to the edge this field is on). Then just map the length of the lists and find the maximum…
Part 2 is even more brute force. It scans all coordinates in the bounding box, calculates the sum of the distances and rejects all fields that have a sum greater than or equal the threshold.
TIL:
Enum.group_byhas a third argument, that can be used to alter the value inserted in the list. Such thatEnum.group_by(input, key_fun, val_fun)is equivalent toinput |> Enum.group_by(key_fun) |> Enum.map({k, values} -> {k, Enum.map(values, val_fun) end)}) |> Enum.into(%{}), well roughly. I think you see what I mean…My code is available at gitlab, as usual:
simon
Today’s challenge is rough. I’ve just completed part 1 after a lot of head scratching before I realised that my issue was in determining what were the infinite coordinates. I too had to resort to a brute-force approach so it will be really interesting to look at some of the other solutions posted as well as José’s code from his stream tomorrow.
I’m going to have a quick look at part 2 but that may become a weekend task. Along with the other ones. This could be where I start to fall behind a bit.
Edit 22 minutes later… Part 2 was way, way easier for me. Fortunately!
My solution is at:
https://github.com/simon-wolf/advent-of-code-2018/blob/master/lib/advent_of_code_2018/day_06.ex
I’m not overly proud of the code but it’s late and I need some sleep!
sorentwo
This one wasn’t pretty. Both solutions were rather brute force, but they completed quickly enough. aoc_2018/lib/aoc/day_06.ex at master · sorentwo/aoc_2018 · GitHub
ryanwinchester
I thought I was doing okay until I went to submit my answer. I can’t figure out what I’m doing wrong, I can get the example/test data to work but not my input. Obviously I’m doing something stupid, but can’t see what.
Can anyone else see what the heck I’m doing wrong?
sasajuric
Looking at your code, it seems you assume that the finite region is a square, when it’s in fact a rectangle. So instead of finding one min-max pair, like you do in line 24, you need two pairs ((xmin, xmax) and (ymin, ymax)), and eliminate coordinates where x == xmin or xmax, or y == ymin or ymax.
theshank
I was being told by AoC site that my answer for part1 is wrong. So I tried @sasajuric 's code from the repo and the output generated was exactly the same.
Here is my input file content.
And the output generated by both mine and @sasajuric 's code is 5047. Can someone else, who has completed the part 1 successfully, please try running this input through their code and share the output…