NobbZ

NobbZ

Advent of Code - Day 3

Note by the Moderators: This topic is to talk about Day 3 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.


And day 3 is solved as well.

On my VM in the office both parts take about 1 to 1.25 seconds. Thats OK for me today. But the first iteration I used to get the actual solutions has some repitions in it, which I do not like.

I really have to iterate on those, and perhaps I’ll be even able to get them more efficient?

First Post!

sorentwo

sorentwo

Oban Core Team

Finding a timely solution for Day 03 took me a little bit. Originally I wanted to use a range to detect overlap, but that wasn’t available so I moved on to constructing sets and counting from there. That wasn’t ideal either, and in the end using a simple map to count tuples was quick enough.

Most Liked

yawaramin

yawaramin

I approached Day 3 as a set intersection problem, the only issue was finding a data structure to represent the claims that would be usable as set elements (i.e. comparable for uniqueness). I realized I could cleanly map each claim to a set of coordinates of the exact square inches of that claim; after that the solution fell into place as a series of set intersections and unions.

Here it is: advent_of_code_2018/lib/day3.ex at d65581aeb7b25f40d22a05c1435b1401b2505fef · yawaramin/advent_of_code_2018 · GitHub

Btw, I thought I’d share this fun fact that Elixir is in the top ten (at 10th) languages being used for Advent of Code projects on GitHub: Repository search results · GitHub

Last Post!

debajit

debajit

My solution for Day 3 Part 1:

I’m reasonably happy with how it turned out.

(I spent quite a bit of time trying to learn how to use the Tensor library (Tensor.Matrix provides matrix operations). I also looked at Matrex, but failed to install it.

In the end I used a simple sparse matrix representation using a map with {row, col} => 1 items to represent the matrix. Using the regex named captures was fun — it was something I learned the hard way from a personal project previously.)

(Haven’t been able to look at Part 2 yet — its late night already, will look at it tomorrow)

Where Next?

Popular in Challenges Top

cblavier
Hi, there :wave: Today, I felt it was way more challenging! I went through part2 thanks to Agent based memoization (without memoization ...
New
ehayun
I have 2 arrays: a1 can be any combination of value or nil like that a1 = [1,nil,3] and array 2 the same a2 = [4,2, nil] How do I com...
New
woolfred
It is that time of the year again: Advent of Code 2022 :christmas_tree: Day 1 Leaderboard:
New
maennchen
Ok, that was a rough one today. I haven’t found a way to improve the algorithm further. Part 1 runs in .5 seconds, Part 2 in ~ 5 minutes...
New
seeplusplus
Hello all, hopefully I post this before someone else does and I don’t dupe. IMO Day 4 was much easier than Day 3 (yay, I can sleep befor...
New
igorb
Today is a brute-force day: advent-of-code-2024/lib/advent_of_code2024/day6.ex at main · ibarakaiev/advent-of-code-2024 · GitHub Takes a...
New
lud
Hello everyone! This year is going to be shorter, but the difficulty will grow faster. Today I already feel that this is not standard “D...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement