Prepare day01 2025

Change-Id: Id3c46f5f552db5a0ba200dedc1ea4e4434932982
This commit is contained in:
2025-12-08 11:43:38 +01:00
parent 49d82b8f90
commit d106e7541d
5 changed files with 301 additions and 2 deletions

View File

@@ -1,9 +1,19 @@
find_package(fmt REQUIRED)
find_package(utf8cpp REQUIRED)
find_package(ctre REQUIRED)
set(HEADERS "") set(HEADERS "")
set(SOURCES "day01.cpp") set(SOURCES "day01.cpp")
add_executable(day01 ${HEADERS} ${SOURCES}) add_executable(day01 ${HEADERS} ${SOURCES})
target_include_directories(day01 PUBLIC ${PROJECT_SOURCE_DIR}) target_include_directories(day01 PUBLIC ${PROJECT_SOURCE_DIR})
target_compile_features(day01 PRIVATE cxx_std_23) target_compile_features(day01 PRIVATE cxx_std_23)
target_link_libraries(day01 PRIVATE ${PLATFORM_LINK_LIBRARIES}) target_link_libraries(day01
PRIVATE
${PLATFORM_LINK_LIBRARIES}
fmt
utf8cpp
ctre
)
target_compile_definitions(day01 PRIVATE ${PLATFORM_DEFINITIONS}) target_compile_definitions(day01 PRIVATE ${PLATFORM_DEFINITIONS})
target_compile_options(day01 PRIVATE ${BASE_OPTIONS}) target_compile_options(day01 PRIVATE ${BASE_OPTIONS})
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${HEADERS} ${SOURCES}) source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${HEADERS} ${SOURCES})

View File

@@ -1,13 +1,88 @@
#include <span> #include <span>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <ranges>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "fmt/std.h"
#include "aoc/types.hpp"
#include "aoc/utils.hpp"
using namespace std::string_view_literals;
using namespace aoc::types;
// simple pipe for std::string by value
template <typename F>
auto operator|(std::string s, F&& f) -> decltype(auto) {
return std::forward<F>(f)(std::move(s));
}
auto ltrim(std::string s) -> std::string {
s.erase(
std::begin(s),
std::find_if(s.begin(), s.end(), [](char ch) {
return !std::isspace(static_cast<char>(ch));
}));
return s;
}
auto rtrim(std::string s) -> std::string {
s.erase(
std::find_if(s.rbegin(), s.rend(), [](char ch) {
return !std::isspace(static_cast<char>(ch));
}).base(),
s.end());
return s;
}
auto trim(std::string s) -> std::string {
return ltrim(rtrim(std::move(s)));
}
// starts at 50
constexpr auto raw_str = R"(
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82
)";
enum class rotdir {
L,
R
};
struct rot {
rotdir dir;
u32 turns;
};
static auto entry([[maybe_unused]]std::span<char const*> const& args) -> void { static auto entry([[maybe_unused]]std::span<char const*> const& args) -> void {
std::string str{raw_str};
str = str | trim;
fmt::print("{}\n", str);
auto rot_vec = str | std::views::split("\n"sv) | std::views::transform([](auto const& str) {
return 0;
}) | std::ranges::to<std::vector>();
} }
auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* argv[]) -> int { auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* argv[]) -> int {
try { try {
entry({argv, std::next(argv, argc)}); entry({argv, std::next(argv, argc)});
} catch (std::exception const& e) { } catch (std::exception const& e) {
(void)e; fmt::print(stderr, "{}\n", e.what());
return 1; return 1;
} }
return 0; return 0;

74
cmake/Findctre.cmake Normal file
View File

@@ -0,0 +1,74 @@
if (DEFINED _FINDCTRE_INCLUDED)
unset(ctre_FOUND CACHE)
unset(ctre_DIR CACHE)
unset(ctre_INCLUDE_DIR CACHE)
unset(ctre_LIBRARIES CACHE)
unset(ctre_VERSION CACHE)
return()
endif()
set(_FINDCTRE_INCLUDED TRUE)
find_package(ctre QUIET)
if (NOT ctre_FOUND)
message(STATUS "ctre not found. Fetching via FetchContent...")
include(FetchContent)
find_program(GIT_EXECUTABLE git)
if (GIT_EXECUTABLE)
set(CTRE_FETCH_METHOD "GIT")
else()
set(CTRE_FETCH_METHOD "ZIP")
endif()
if (CTRE_FETCH_METHOD STREQUAL "GIT")
FetchContent_Declare(
ctre
GIT_REPOSITORY https://github.com/hanickadot/compile-time-regular-expressions.git
GIT_TAG v3.10.0
)
else()
FetchContent_Declare(
ctre
URL https://github.com/hanickadot/compile-time-regular-expressions/archive/refs/tags/v3.10.0.zip
)
endif()
# Turn off BUILD_TESTING globally to prevent CTest from being included in CTRE
set(BUILD_TESTING OFF CACHE BOOL "Disable testing globally" FORCE)
# Set the CTRE_BUILD_TESTS option before including the CTRE library
set(CTRE_BUILD_TESTS OFF CACHE BOOL "Build ctre Tests" FORCE)
FetchContent_MakeAvailable(ctre)
else()
message(STATUS "ctre found.")
# Ensure we have a usable target
if (NOT TARGET ctre::ctre)
if (TARGET ctre)
add_library(ctre::ctre ALIAS ctre)
else()
message(FATAL_ERROR "ctre was found, but no CMake target 'ctre' or 'ctre::ctre' exists.")
endif()
endif()
# Populate the standard variables
set(ctre_FOUND TRUE)
set(ctre_LIBRARIES ctre::ctre)
get_target_property(_ctre_inc ctre::ctre INTERFACE_INCLUDE_DIRECTORIES)
set(ctre_INCLUDE_DIR "${_ctre_inc}")
endif()
if (NOT TARGET ctre::ctre)
if (TARGET ctre)
add_library(ctre::ctre ALIAS ctre)
else()
message(FATAL_ERROR "Could not find or fetch ctre; no target ctre or ctre::ctre available")
endif()
endif()
set(ctre_FOUND TRUE)
set(ctre_LIBRARIES ctre::ctre)
set(ctre_VERSION "${ctre_VERSION}") # this comes from the ctre project
get_target_property(_ctre_inc ctre::ctre INTERFACE_INCLUDE_DIRECTORIES)
set(ctre_INCLUDE_DIR "${_ctre_inc}")

70
cmake/Findfmt.cmake Normal file
View File

@@ -0,0 +1,70 @@
if (DEFINED _FINDFMT_INCLUDED)
unset(fmt_FOUND CACHE)
unset(fmt_DIR CACHE)
unset(fmt_INCLUDE_DIR CACHE)
unset(fmt_LIBRARIES CACHE)
unset(fmt_VERSION CACHE)
return()
endif()
set(_FINDFMT_INCLUDED TRUE)
find_package(fmt QUIET)
if (NOT fmt_FOUND)
message(STATUS "fmt not found. Fetching via FetchContent...")
include(FetchContent)
find_program(GIT_EXECUTABLE git)
if (GIT_EXECUTABLE)
set(FMT_FETCH_METHOD "GIT")
else()
set(FMT_FETCH_METHOD "ZIP")
endif()
if (FMT_FETCH_METHOD STREQUAL "GIT")
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 12.0.0
)
else()
FetchContent_Declare(
fmt
URL https://github.com/fmtlib/fmt/releases/download/12.0.0/fmt-12.0.0.zip
)
endif()
FetchContent_MakeAvailable(fmt)
else()
message(STATUS "fmt found.")
# Ensure we have a usable target
if (NOT TARGET fmt::fmt)
if (TARGET fmt)
add_library(fmt::fmt ALIAS fmt)
else()
message(FATAL_ERROR "fmt was found, but no CMake target 'fmt' or 'fmt::fmt' exists.")
endif()
endif()
# Populate the standard variables
set(fmt_FOUND TRUE)
set(fmt_LIBRARIES fmt::fmt)
get_target_property(_fmt_inc fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
set(fmt_INCLUDE_DIR "${_fmt_inc}")
endif()
if (NOT TARGET fmt::fmt)
if (TARGET fmt)
add_library(fmt::fmt ALIAS fmt)
else()
message(FATAL_ERROR "Could not find or fetch fmt; no target fmt or fmt::fmt available")
endif()
endif()
set(fmt_FOUND TRUE)
set(fmt_LIBRARIES fmt::fmt)
set(fmt_VERSION "${fmt_VERSION}") # this comes from the fmt project
get_target_property(_fmt_inc fmt::fmt INTERFACE_INCLUDE_DIRECTORIES)
set(fmt_INCLUDE_DIR "${_fmt_inc}")

70
cmake/Findutf8cpp.cmake Normal file
View File

@@ -0,0 +1,70 @@
if (DEFINED _FINDUTF8CPP_INCLUDED)
unset(utf8cpp_FOUND CACHE)
unset(utf8cpp_DIR CACHE)
unset(utf8cpp_INCLUDE_DIR CACHE)
unset(utf8cpp_LIBRARIES CACHE)
unset(utf8cpp_VERSION CACHE)
return()
endif()
set(_FINDUTF8CPP_INCLUDED TRUE)
find_package(utf8cpp QUIET)
if (NOT utf8cpp_FOUND)
message(STATUS "utf8cpp not found. Fetching via FetchContent...")
include(FetchContent)
find_program(GIT_EXECUTABLE git)
if (GIT_EXECUTABLE)
set(UTF8CPP_FETCH_METHOD "GIT")
else()
set(UTF8CPP_FETCH_METHOD "ZIP")
endif()
if (UTF8CPP_FETCH_METHOD STREQUAL "GIT")
FetchContent_Declare(
utf8cpp
GIT_REPOSITORY https://github.com/nemtrif/utfcpp.git
GIT_TAG v4.0.6
)
else()
FetchContent_Declare(
utf8cpp
URL https://github.com/nemtrif/utfcpp/archive/refs/tags/v4.0.6.zip
)
endif()
FetchContent_MakeAvailable(utf8cpp)
else()
message(STATUS "utf8cpp found.")
# Ensure we have a usable target
if (NOT TARGET utf8cpp::utf8cpp)
if (TARGET utf8cpp)
add_library(utf8cpp::utf8cpp ALIAS utf8cpp)
else()
message(FATAL_ERROR "utf8cpp was found, but no CMake target 'utf8cpp' or 'utf8cpp::utf8cpp' exists.")
endif()
endif()
# Populate the standard variables
set(utf8cpp_FOUND TRUE)
set(utf8cpp_LIBRARIES utf8cpp::utf8cpp)
get_target_property(_utf8cpp_inc utf8cpp::utf8cpp INTERFACE_INCLUDE_DIRECTORIES)
set(utf8cpp_INCLUDE_DIR "${_utf8cpp_inc}")
endif()
if (NOT TARGET utf8cpp::utf8cpp)
if (TARGET utf8cpp)
add_library(utf8cpp::utf8cpp ALIAS utf8cpp)
else()
message(FATAL_ERROR "Could not find or fetch utf8cpp; no target utf8cpp or utf8cpp::utf8cpp available")
endif()
endif()
set(utf8cpp_FOUND TRUE)
set(utf8cpp_LIBRARIES utf8cpp::utf8cpp)
set(utf8cpp_VERSION "${utf8cpp_VERSION}") # this comes from the utf8cpp project
get_target_property(_utf8cpp_inc utf8cpp::utf8cpp INTERFACE_INCLUDE_DIRECTORIES)
set(utf8cpp_INCLUDE_DIR "${_utf8cpp_inc}")