From 1fd2a6b7ff79460d65e3cffd8c49163908a62b4c Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Tue, 27 Aug 2024 14:51:52 -0700 Subject: [PATCH] 2015_10 --- 2015/10.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++ 2015/CMakeLists.txt | 3 +++ CMakeLists.txt | 2 +- CMakePresets.json | 8 +++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 2015/10.cpp diff --git a/2015/10.cpp b/2015/10.cpp new file mode 100644 index 0000000..c64bddb --- /dev/null +++ b/2015/10.cpp @@ -0,0 +1,53 @@ +#include +#include + +#include +#include +#include +#include +#include + +auto seesay(std::string_view const input) -> std::string +{ + std::string output; + for (auto cursor = begin(input); cursor != end(input);) + { + auto const c = *cursor; + auto const cursor_ = std::find_if(std::next(cursor), end(input), [c](auto const x) { return x != c; }); + auto const count = std::distance(cursor, cursor_); + (output += std::to_string(count)) += c; + cursor = cursor_; + } + return output; +} + +TEST_SUITE("documented examples") { +using namespace std::string_view_literals; + +TEST_CASE("unit tests") { + REQUIRE_EQ(seesay("1"sv), "11"sv); + REQUIRE_EQ(seesay("11"sv), "21"sv); + REQUIRE_EQ(seesay("21"sv), "1211"sv); + REQUIRE_EQ(seesay("1211"sv), "111221"sv); + REQUIRE_EQ(seesay("111221"sv), "312211"sv); +} + +} + +auto Main(std::istream &in, std::ostream &out) -> void +{ + std::string line; + std::size_t part1 = 0, part2 = 0; + + std::getline(in, line); + + for (int i = 0; i < 40; i++) { + line = seesay(line); + } + out << "Part 1: " << line.size() << std::endl; + + for (int i = 0; i < 10; i++) { + line = seesay(line); + } + out << "Part 2: " << line.size() << std::endl; +} diff --git a/2015/CMakeLists.txt b/2015/CMakeLists.txt index 1238335..b505293 100644 --- a/2015/CMakeLists.txt +++ b/2015/CMakeLists.txt @@ -6,3 +6,6 @@ target_link_libraries(2015_02 aocpp) add_executable(2015_08 08.cpp) target_link_libraries(2015_08 aocpp) + +add_executable(2015_10 10.cpp) +target_link_libraries(2015_10 aocpp) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93bd855..ecf9198 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ endif() find_package(PkgConfig) pkg_check_modules(GMP REQUIRED IMPORTED_TARGET gmpxx) pkg_check_modules(Z3 REQUIRED IMPORTED_TARGET z3) -find_package(Boost REQUIRED) +find_package(Boost REQUIRED CONFIG) add_subdirectory(lib) add_subdirectory(dlx) diff --git a/CMakePresets.json b/CMakePresets.json index e1b73b5..cc4bce1 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -13,5 +13,13 @@ "CMAKE_EXPORT_COMPILE_COMMANDS": "On" } } + ], + "buildPresets": [ + { + "name": "build", + "description": "", + "displayName": "", + "configurePreset": "build" + } ] }