Line data Source code
1 : #include "PuzzleImpl.h"
2 :
3 : #include "Grid2d.h"
4 : #include "LinewiseInput.h"
5 : #include "Views.h"
6 :
7 : #include <experimental/mdspan>
8 : #include <fmt/format.h>
9 : #include <fmt/ranges.h>
10 :
11 : #include <vector>
12 :
13 : namespace {
14 1 : auto parse(std::string_view const input) {
15 1 : std::vector<uint32_t> locks;
16 1 : std::vector<uint32_t> keys;
17 :
18 500 : for (auto &&r : input | views::split("\n\n"sv)) {
19 500 : Grid2dSpan<char const> g(r.data(), 5, 7, 1, 6);
20 500 : uint32_t bits = 0;
21 3000 : for (int y = 1; y < g.ySize() - 1; ++y)
22 15000 : for (int x = 0; x < g.xSize(); ++x) {
23 12500 : bits |= g[x, y] == '#' ? 1u : 0u;
24 12500 : bits <<= 1u;
25 12500 : }
26 500 : if (g[0, 0] == '#')
27 250 : keys.push_back(bits);
28 250 : else
29 250 : locks.push_back(bits);
30 500 : }
31 :
32 1 : return std::make_tuple(std::move(locks), std::move(keys));
33 1 : }
34 : } // namespace
35 :
36 1 : template <> std::string solvePart1<2024, 25>(std::string_view const input) {
37 1 : auto [locks, keys] = parse(input);
38 1 : size_t ctr = 0;
39 1 : for (auto l : locks)
40 250 : for (auto k : keys)
41 62500 : if ((l & k) == 0u)
42 2854 : ++ctr;
43 1 : return std::to_string(ctr);
44 1 : }
45 :
46 1 : template <> std::string solvePart2<2024, 25>(std::string_view const /* input */) { return ""s; }
47 :
48 1 : template <> std::string_view solution1<2024, 25>() { return "2854"sv; }
49 1 : template <> std::string_view solution2<2024, 25>() { return ""sv; }
|