This commit is contained in:
Eric Mertens 2024-08-27 14:51:52 -07:00
parent ffa57208d5
commit 1fd2a6b7ff
4 changed files with 65 additions and 1 deletions

53
2015/10.cpp Normal file
View File

@ -0,0 +1,53 @@
#include <aocpp/Startup.hpp>
#include <doctest.h>
#include <algorithm>
#include <cstddef>
#include <iterator>
#include <stdexcept>
#include <string_view>
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;
}

View File

@ -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)

View File

@ -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)

View File

@ -13,5 +13,13 @@
"CMAKE_EXPORT_COMPILE_COMMANDS": "On"
}
}
],
"buildPresets": [
{
"name": "build",
"description": "",
"displayName": "",
"configurePreset": "build"
}
]
}