aoc24: day03 tokenizer
This commit is contained in:
15
sol/24/01/CMakeLists.txt
Normal file
15
sol/24/01/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
set(HEADERS "")
|
||||
set(SOURCES entry.cpp)
|
||||
add_executable(sol2401 ${HEADERS} ${SOURCES})
|
||||
target_include_directories(sol2401 PRIVATE ${PROJECT_SOURCE_DIR})
|
||||
target_compile_features(sol2401 PRIVATE cxx_std_23)
|
||||
target_compile_options(sol2401 PRIVATE ${BASE_OPTIONS})
|
||||
target_compile_definitions(sol2401 PRIVATE ${BASE_DEFINITIONS})
|
||||
target_link_libraries(sol2401
|
||||
PRIVATE
|
||||
aoc
|
||||
)
|
||||
set_target_properties(sol2401 PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
|
||||
)
|
||||
source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${HEADERS} ${SOURCES})
|
||||
61
sol/24/01/entry.cpp
Normal file
61
sol/24/01/entry.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "aoc/aoc.hpp"
|
||||
#include "fmt/format.h"
|
||||
|
||||
// auto aoc::entry([[maybe_unused]]std::vector<std::string_view> const& args) -> void {
|
||||
// constexpr auto filename = "./dat/24/re/01.txt";
|
||||
// std::ifstream strm{filename, std::ios::in};
|
||||
// if (!strm.is_open()) {
|
||||
// fmt::print("Error opening file: {}\n", filename);
|
||||
// return 1;
|
||||
// }
|
||||
//
|
||||
// std::vector<std::uint32_t> a{};
|
||||
// std::vector<std::uint32_t> b{};
|
||||
//
|
||||
// std::string str{};
|
||||
// while (strm) {
|
||||
// auto const c = char(strm.peek());
|
||||
// if (std::isdigit(c)) {
|
||||
// str += char(strm.get());
|
||||
// continue;
|
||||
// }
|
||||
// if (c == ' ') {
|
||||
// if (!str.empty()) {
|
||||
// a.emplace_back(std::stoi(str));
|
||||
// str.clear();
|
||||
// }
|
||||
// }
|
||||
// if (c == '\n') {
|
||||
// if (!str.empty()) {
|
||||
// b.emplace_back(std::stoi(str));
|
||||
// str.clear();
|
||||
// }
|
||||
// }
|
||||
// [[discard]]strm.get();
|
||||
// }
|
||||
//
|
||||
// fmt::print("a: {}, b: {}\n", a.size(), b.size());
|
||||
//
|
||||
// std::sort(std::begin(a), std::end(a));
|
||||
// std::sort(std::begin(b), std::end(b));
|
||||
//
|
||||
// auto diff_view = std::views::zip(a, b) | std::views::transform([](auto const& p) {
|
||||
// auto const [x, y] = p;
|
||||
// return x > y ? x - y : y - x;
|
||||
// });
|
||||
// auto const sum = std::accumulate(std::begin(diff_view), std::end(diff_view), 0);
|
||||
//
|
||||
// fmt::print("Part A: {}\n", std::abs(sum));
|
||||
//
|
||||
// auto values = a | std::views::transform([&b](auto v) {
|
||||
// return std::pair{v, b | std::views::filter([v](auto c) {
|
||||
// return v == c; // Filter elements in `b` equal to `v`
|
||||
// }) | std::ranges::to<std::vector>()};
|
||||
// }) | std::ranges::to<std::vector>();
|
||||
//
|
||||
// auto const meow = std::accumulate(std::begin(values), std::end(values), 0, [](auto const acc, auto const& pair) {
|
||||
// return acc + std::int32_t(pair.first * pair.second.size());
|
||||
// });
|
||||
//
|
||||
// fmt::print("Part B: {}\n", meow);
|
||||
// }
|
||||
Reference in New Issue
Block a user