Prepare day01 2025
Change-Id: Id3c46f5f552db5a0ba200dedc1ea4e4434932982
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
find_package(fmt REQUIRED)
|
||||
find_package(utf8cpp REQUIRED)
|
||||
find_package(ctre REQUIRED)
|
||||
|
||||
set(HEADERS "")
|
||||
set(SOURCES "day01.cpp")
|
||||
add_executable(day01 ${HEADERS} ${SOURCES})
|
||||
target_include_directories(day01 PUBLIC ${PROJECT_SOURCE_DIR})
|
||||
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_options(day01 PRIVATE ${BASE_OPTIONS})
|
||||
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${HEADERS} ${SOURCES})
|
||||
|
||||
@@ -1,13 +1,88 @@
|
||||
#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 {
|
||||
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 {
|
||||
try {
|
||||
entry({argv, std::next(argv, argc)});
|
||||
} catch (std::exception const& e) {
|
||||
(void)e;
|
||||
fmt::print(stderr, "{}\n", e.what());
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user