Line data Source code
1 : #include "Grid2d.h"
2 : #include "Intcode.h"
3 : #include "IntegerCast.h"
4 : #include "LinewiseInput.h"
5 : #include "PuzzleImpl.h"
6 :
7 : #include <algorithm>
8 : #include <chrono>
9 : #include <iostream>
10 : #include <limits>
11 : #include <queue>
12 : #include <stack>
13 : #include <thread>
14 :
15 : namespace {
16 : using Coord = Vec2<int>;
17 : constexpr std::array<Coord, 4u> stencil = {{{0, 1}, {1, 0}, {0, -1}, {-1, 0}}};
18 : } // namespace
19 :
20 1 : template <> size_t part1<2019, 17>(std::string_view const input) {
21 1 : Computer c(input);
22 1 : std::string output;
23 1711 : c.registerOutput([&](int64_t v) { output.push_back(static_cast<char>(v)); });
24 1 : ASSERT(c.run() == Computer::HALTED);
25 1 : output.pop_back(); // remove last newline
26 1 : Grid2d<char> grid = LinewiseInput{output}.makeCharGrid2dWithGhostLayers(1, '.');
27 1 : int64_t result = 0;
28 46 : for (Coord c{0, 0}; c.y() < grid.ySize(); ++c.y())
29 1710 : for (c.x() = 0; c.x() < grid.xSize(); ++c.x()) {
30 1665 : if (grid[c] == '#' &&
31 1665 : std::ranges::count_if(stencil, [&](auto const &s) { return grid[c + s] == '#'; }) >= 3) {
32 12 : grid[c] = 'O';
33 12 : result += integerCast<int64_t>(c.x() * (grid.ySize() - c.y() - 1));
34 12 : }
35 1665 : }
36 :
37 1 : return result;
38 1 : }
39 :
40 1 : template <> size_t part2<2019, 17>(std::string_view const /*input*/) { return 0; }
|