30

Day 1: Dusty Shed

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

you are viewing a single comment's thread
view the rest of the comments
[-] addie@feddit.uk 4 points 1 day ago

C++

I'd have to check back through them, but they tend to be pretty easy on the first day; let the people that are using Excel get a win. 12 days again this year, so they should ramp up pretty quick - I actually preferred that last year, keep it short and sweet, no filler.

Solved by counting the entries in a hash map, then sorting it. 90 microseconds.

auto parts(const std::vector<int>& input) {
  auto count = boost::unordered_flat_map<int, int>{1000};
  for (const auto& entry : input)
    ++count[entry];
  auto sort = std::vector<std::pair<int, int>>{count.begin(), count.end()};
  std::sort(sort.begin(), sort.end(), [](auto& a, auto& b) {
    return a.second > b.second;
  });
  auto part1 = sort[0].first * sort[1].first * sort[2].first;
  auto size = sort.size();
  auto part2 =
    sort[size - 1].first * sort[size - 2].first * sort[size - 3].first;
  return std::pair{part1, part2};
}
[-] eco_game@discuss.tchncs.de 1 points 1 day ago

Is there any benefit of using the boost map instead of a standard std one?

[-] addie@feddit.uk 3 points 1 day ago

It's about fifty times faster, since it doesn't make the specification-required mistakes in the standard one. (Specifically, iteration in constant time. The Boost one is 'always faster', but not constant. Constant time requires maintaining a separate linked list of all entries, which wastes time and memory.)

For this; no, makes no difference. The problem space is so small that the standard maps are quite fast enough. Just force it habit to never use them.

[-] eco_game@discuss.tchncs.de 2 points 1 day ago

Ah ok interesting, thanks. My C++ lecture hasn't touched on external? libraries yet.

this post was submitted on 01 Dec 2026
30 points (100.0% liked)

Advent Of Code

1262 readers
48 users here now

An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Everybody Codes is another collection of programming puzzles with seasonal events.

EC 2025

AoC 2026

Solution Threads

M T W T F S S
1 2 3 4 5 6
7 8 9 10 11 12

Visualisations Megathread

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 3 years ago
MODERATORS