summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOrfeas <38209077+0xfea5@users.noreply.github.com>2025-09-02 13:23:08 +0300
committerOrfeas <38209077+0xfea5@users.noreply.github.com>2025-09-02 13:46:18 +0300
commit50d538760838094218642c30b72d402dff1d2ae5 (patch)
tree1d8f63fc3252c55f24fed1da8936887e93951f93
parentDelete input.txt files (diff)
downloadaoc24-50d538760838094218642c30b72d402dff1d2ae5.tar.gz
aoc24-50d538760838094218642c30b72d402dff1d2ae5.zip
day02: move lambdas out of loop
-rw-r--r--day04/solution.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/day04/solution.cpp b/day04/solution.cpp
index 6fa5ccd..fe33120 100644
--- a/day04/solution.cpp
+++ b/day04/solution.cpp
@@ -51,27 +51,27 @@ void part1(auto input) {
51 views::zip(decr, decr), // top-left 51 views::zip(decr, decr), // top-left
52 }; 52 };
53 53
54 for (const auto [i, j] : 54 auto in_bounds = [width, height](IndexPair e) -> bool {
55 auto &&[i, j] = e;
56 return 0 <= i and i < height and 0 <= j and j < width;
57 };
58
59 auto get_input_element = [input](IndexPair e) -> char {
60 auto &&[i, j] = e;
61 return input[i][j];
62 };
63
64 for (auto &&[i, j] :
55 views::cartesian_product(views::iota(0, width), 65 views::cartesian_product(views::iota(0, width),
56 views::iota(0, height))) { 66 views::iota(0, height))) {
57 67
68 auto add_offset = [i, j](IndexPair e) {
69 const auto [di, dj] = e;
70 return IndexPair{i + di, j + dj};
71 };
72
58 // std::apply is needed to unfold the ‘directions’ tuple. 73 // std::apply is needed to unfold the ‘directions’ tuple.
59 std::apply([=, &answer](auto &&... dirs) { 74 std::apply([=, &answer](auto &&... dirs) {
60 auto add_offset = [i, j](IndexPair e) {
61 const auto [di, dj] = e;
62 return std::tuple{i + di, j + dj};
63 };
64
65 auto in_bounds = [width, height](IndexPair e) -> bool {
66 const auto [i, j] = e;
67 return 0 <= i and i < height and 0 <= j and j < width;
68 };
69
70 auto get_input_element = [input](IndexPair e) -> char {
71 const auto [i, j] = e;
72 return input[i][j];
73 };
74
75 (((answer += ranges::equal(dirs 75 (((answer += ranges::equal(dirs
76 | views::transform(add_offset) 76 | views::transform(add_offset)
77 | views::filter(in_bounds) 77 | views::filter(in_bounds)