JEG2

JEG2

Author of Designing Elixir Systems with OTP

Advent of Code - Day 11

Note: This topic is to talk about Day 11 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.

Most Liked

JEG2

JEG2

Author of Designing Elixir Systems with OTP

Here’s my Day 11 solution:

The key idea is the use of a summed area table. You can watch a video of me struggling to learn this data structure (for the next 14 days):

simon

simon

You’re committed to writing it now after saying that! :joy:

sasajuric

sasajuric

Author of Elixir In Action

I also did it using summed area table. My solution is here.

simon

simon

I’d not heard of a summed area table before checking this thread (one of the perils of having a history degree rather than a maths or CS one I guess!) so my first attempt was done by brute-force but was so slow that I left it to run over-night. It did give me the right answer however.

This morning I refactored my code to use a summed area table and part 2 runs in around 5 seconds. I’m not sure if that’s good or not.

Anyway, my code is here and it’s probably very similar to the other solutions everyone has come up with.

simon

simon

I tried a similar thing with my own algorithm when calculating the totals for the different square sizes (and this would be most beneficial for larger ones). As you move across the grid you could subtract the total of the previous column of relevant rows and add the total of the newly included column of relevant rows and then do a similar thing for rows when doing the y-axis.

So, for a 3x3 square with an original of 0,0 you’d have a total made up from:

0,0  1,0  2,0
0,1  1,1  2,1
0,2  1,2  2,2

When the origin becomes 1,0 you could remove the sum of 0,0 0,1 and 0,2 and add 3,0 3,1 and 3,2.

However, because is was 2am at that point I decided to stop and just let it run over-night!

I like your stream idea and I must look into doing more with them.

And yes, I should add concurrency too to speed my code up.

Where Next?

Popular in Challenges Top

Aetherus
This topic is about Day 5 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/le...
New
Aetherus
This topic is about Day 7 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/le...
New
stevensonmt
Trying to get more facility with dynamic programming concepts on Leetcode and having an issue I can’t find a way around. It’s a chutes an...
New
Aetherus
Hello, guys. I’m back again, but only for the weekends, maybe. This topic is about Day 13 of the Advent of Code 2020 . Thanks to @egze,...
New
woolfred
It is that time of the year again: Advent of Code 2022 :christmas_tree: Day 1 Leaderboard:
New
connorlay
Note by the Moderators: This topic is for general discussion about the Advent of Code 2018. To prevent people from being spoiled about s...
New
bjorng
Note: This topic is to talk about Day 6 of the Advent of Code 2019. There is a private leaderboard for elixirforum members. You can join...
New
code-shoily
Here’s my day 3 code This was quite easy. I was afraid Part 2 would be “un-regex-able” and was preparing for hand crafting automata bu...
New
mattbaker
I’m having so much fun working on the “Protohackers” challenges, I never got into Advent of Code much but this has been amazing. The chal...
New
cblavier
Hi, there :wave: Today, I felt it was way more challenging! I went through part2 thanks to Agent based memoization (without memoization ...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement