2025D01P1: done
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
#include <span>
|
#include <span>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
|
||||||
#include <numeric>
|
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@@ -45,7 +43,7 @@ auto trim(std::string s) -> std::string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// starts at 50
|
// starts at 50
|
||||||
constexpr auto raw_str = R"(
|
[[maybe_unused]]constexpr auto raw_str = R"(
|
||||||
L68
|
L68
|
||||||
L30
|
L30
|
||||||
R48
|
R48
|
||||||
@@ -59,6 +57,7 @@ L82
|
|||||||
)";
|
)";
|
||||||
|
|
||||||
enum class rotdir {
|
enum class rotdir {
|
||||||
|
none,
|
||||||
L,
|
L,
|
||||||
R
|
R
|
||||||
};
|
};
|
||||||
@@ -68,14 +67,48 @@ struct rot {
|
|||||||
u32 turns;
|
u32 turns;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto map_char_to_rotdir(char c) -> rotdir {
|
||||||
|
switch (c) {
|
||||||
|
using enum rotdir;
|
||||||
|
case 'L': return L;
|
||||||
|
case 'R': return R;
|
||||||
|
default: return none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto map_dir_to_i32(i32 value, rotdir dir) -> i32 {
|
||||||
|
switch (dir) {
|
||||||
|
using enum rotdir;
|
||||||
|
case L: return -value;
|
||||||
|
case R:
|
||||||
|
default: return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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};
|
// std::string str{raw_str};
|
||||||
str = str | trim;
|
// str = str | trim;
|
||||||
fmt::print("{}\n", str);
|
auto str = aoc::read_text("./input.txt").value_or("") | trim;
|
||||||
|
|
||||||
auto rot_vec = str | std::views::split("\n"sv) | std::views::transform([](auto const& str) {
|
auto rot_vec = str | std::views::split("\n"sv) | std::views::transform([](auto const& str) {
|
||||||
return 0;
|
return rot{
|
||||||
|
.dir = map_char_to_rotdir(*std::begin(str)),
|
||||||
|
.turns = u32(std::stoul(std::string{++std::begin(str), std::end(str)}))
|
||||||
|
};
|
||||||
}) | std::ranges::to<std::vector>();
|
}) | std::ranges::to<std::vector>();
|
||||||
|
|
||||||
|
i32 start = 50;
|
||||||
|
auto sum = std::ranges::fold_left(rot_vec, 0, [&start](auto a, auto b) {
|
||||||
|
auto c = map_dir_to_i32(b.turns % 100, b.dir);
|
||||||
|
|
||||||
|
start = (100 + start + c) % 100;
|
||||||
|
|
||||||
|
if (start == 0) ++a;
|
||||||
|
|
||||||
|
return a;
|
||||||
|
});
|
||||||
|
|
||||||
|
fmt::print("res: {}\n", sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* argv[]) -> int {
|
auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* argv[]) -> int {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ if(NOT MSVC)
|
|||||||
set(BASE_OPTIONS
|
set(BASE_OPTIONS
|
||||||
-Wall
|
-Wall
|
||||||
-Wextra
|
-Wextra
|
||||||
-Werror
|
# -Werror
|
||||||
# fmt warnings
|
# fmt warnings
|
||||||
-Wno-deprecated-literal-operator
|
-Wno-deprecated-literal-operator
|
||||||
)
|
)
|
||||||
@@ -90,7 +90,7 @@ if(NOT MSVC)
|
|||||||
else()
|
else()
|
||||||
set(BASE_OPTIONS
|
set(BASE_OPTIONS
|
||||||
/W4
|
/W4
|
||||||
/WX # warnings as errors (MSVC equivalent of -Werror)
|
# /WX # warnings as errors (MSVC equivalent of -Werror)
|
||||||
/utf-8
|
/utf-8
|
||||||
/Zc:__cplusplus
|
/Zc:__cplusplus
|
||||||
#/fsanitize=address # Doesn't work without Visual Studio
|
#/fsanitize=address # Doesn't work without Visual Studio
|
||||||
|
|||||||
Reference in New Issue
Block a user