From 109a964cb521ddd9e5212e5be02ed046240866b2 Mon Sep 17 00:00:00 2001 From: Mars Ultor Date: Sat, 6 Dec 2025 14:10:31 -0600 Subject: [PATCH] done with day 6 part 1 --- src/day-6-solution.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/day-6-solution.cpp diff --git a/src/day-6-solution.cpp b/src/day-6-solution.cpp new file mode 100644 index 0000000..ef34c2e --- /dev/null +++ b/src/day-6-solution.cpp @@ -0,0 +1,81 @@ +#include "spdlog/spdlog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum class Operation { + ADD='+', MULTIPLY='*' +}; + + +uint_fast64_t part_one_solve_worksheet(const std::vector, Operation>>& worksheet){ + uint_fast64_t running_sum = uint_fast64_t {0}; + for (std::vector,Operation>>::const_iterator i = worksheet.cbegin(); ifirst.begin(); + switch (i->second) { + case Operation::ADD : + for (std::vector::const_iterator j = i->first.cbegin()+1; j< i->first.cend(); j++) { + current_calc+= *j; + } + break; + case Operation::MULTIPLY: + for (std::vector::const_iterator j = i->first.cbegin()+1; j< i->first.cend() ; j++) { + current_calc*= *j; + } + } + running_sum+=current_calc; + } + return running_sum; +} +std::vector, Operation>> part_one_parse(std::ifstream& input_file){ + + std::vector, Operation>> worksheet = std::vector, Operation>> {}; + std::string current_line = std::string{}; + while (std::getline(input_file, current_line)) { + +std::string_view current_line_string_view = std::string_view{current_line}; + auto split_view = std::ranges::views::split(current_line_string_view, ' '); + + std::vector groups = std::vector{}; + for (auto&& token : split_view) { + if(token.empty()) continue; + groups.push_back(std::string_view{token}); + } + + if(worksheet.empty()) worksheet.assign(groups.size(), std::pair, Operation> { std::vector {}, Operation::ADD }); + + if(input_file.peek()==EOF){ + + for (std::vector::const_iterator i = groups.begin(); i(i-groups.begin())].second = static_cast(*(i->begin())); + } + + }else{ + for (std::vector::const_iterator i = groups.begin(); idata(), i->data() + i->size(), value); + worksheet[static_cast(i-groups.begin())].first.push_back(value); + } + } + } + input_file.seekg(0); + return worksheet; +} + + +int main (int argc, char *argv[]) { + std::ifstream input_file = std::ifstream{"testcases/day-6.in"}; + std::vector, Operation>> part_one_worksheet = part_one_parse(input_file); + spdlog::info("Number of problems captured: {}", part_one_worksheet.size()); + uint_fast64_t part_one_result = part_one_solve_worksheet(part_one_worksheet); + spdlog::info("Part one solution: {}", part_one_result); + return 0; +}