diff --git a/day20/day20.cpp b/day20/day20.cpp index ccc72b0..e04e8cd 100644 --- a/day20/day20.cpp +++ b/day20/day20.cpp @@ -5,12 +5,10 @@ #include #include #include -#include #include #include #include #include -#include #include constexpr auto TILE_ID_PATTERN = R"(Tile (\d+):)"; @@ -206,7 +204,7 @@ class TransformGenerator { class const_iterator { public: using difference_type = int; - using value_type = std::function; + using value_type = CameraFrame; using pointer = const value_type *; using reference = const value_type &; using iterator_category = std::input_iterator_tag; @@ -231,7 +229,8 @@ class TransformGenerator { } const value_type operator*() { - return *(this->baseIterator); + auto transform = *(this->baseIterator); + return transform(); } private: @@ -239,12 +238,12 @@ class TransformGenerator { const_iterator(const TransformGenerator &container) : container(container), baseIterator(container.operationList.cbegin()) { } - const_iterator(const TransformGenerator &container, const std::vector::const_iterator &baseIterator) + const_iterator(const TransformGenerator &container, const std::vector>::const_iterator &baseIterator) : container(container), baseIterator(baseIterator) { } const TransformGenerator &container; - std::vector::const_iterator baseIterator; + std::vector>::const_iterator baseIterator; }; TransformGenerator(const CameraFrame &frame) @@ -415,15 +414,14 @@ bool isBoardFilled(const std::map, CameraFrame> board, int m std::optional findPossibleFrame( const CameraFrame &frameToMatch, std::function frameMatches) { auto transformations = TransformGenerator(frameToMatch); - auto result = std::find_if(transformations.cbegin(), transformations.cend(), [frameMatches](auto transformation) { - CameraFrame transformedFrame = transformation(); + auto result = std::find_if(transformations.cbegin(), transformations.cend(), [frameMatches](CameraFrame transformedFrame) { return frameMatches(transformedFrame); }); if (result == transformations.cend()) { return std::nullopt; } - return (*result)(); + return *result; } /** @@ -502,8 +500,7 @@ std::map, CameraFrame> findLinedUpArrangement(const std::vec const TransformGenerator transforms(frame); for (auto it = transforms.cbegin(); it != transforms.cend(); ++it) { - auto transformation = *it; - CameraFrame transformedFrame = transformation(); + CameraFrame transformedFrame = *it; auto res = findLinedUpArrangement(transformedFrame, availableFrames, boardSize, boardSize); if (res) { return *res; @@ -618,7 +615,7 @@ long part2(const std::map, CameraFrame> &rawBoard, int board auto transforms = TransformGenerator(fullBoardFrame); for (auto it = transforms.cbegin(); it != transforms.cend(); it++) { - auto transformedFrame = (*it)(); + auto transformedFrame = *it; int totalMonsterChars = 0; for (int i = 0; i < fullBoard.size() - monsterDimensions.first; i++) { for (int j = 0; j < fullBoard.at(0).size() - monsterDimensions.second; j++) {