JEG2
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
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
You’re committed to writing it now after saying that! 
sasajuric
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
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.







