#include "AdventHelpers/AdventOfCodeSolution.h" #include #include #include #include #include #include class BatteryBank { public: using joltage_t = uint64_t; using bank_t = std::vector; BatteryBank(std::string bankinput) { mBank.reserve(bankinput.length()); for (const auto& c : bankinput) { const int value = c - '0'; mBankCounts[value]++; mBank.push_back(value); } mJoltage = calculateJoltage(); } inline std::vector bank() const { return mBank; } inline joltage_t joltage() const { return mJoltage; } void printMd() const { for (int i = 0; i < mBank.size(); i++) { if (i == mLeftIndex || i == mRightIndex) { std::cout << "**" << std::to_string(mBank[i]) << "**"; } else { std::cout << std::to_string(mBank[i]); } } std::cout << std::endl; } private: joltage_t calculateJoltage() { // Find the max value, excluding the last const auto maxIter = std::max_element(mBank.begin(), mBank.end()-1); const auto maxVal = *maxIter; // Find the farthest left that's the max auto leftIter = mBank.begin(); while (*leftIter != maxVal) leftIter++; // Roll right and figure out what's the next biggest and send that const auto rightIter = std::max_element(leftIter + 1, mBank.end()); const auto rightVal = *rightIter; mLeftIndex = leftIter - mBank.begin(); mRightIndex = rightIter - mBank.begin(); return (maxVal * 10) + rightVal; } joltage_t calculateJoltageWithFriction() { } std::unordered_map mBankCounts; bank_t mBank; joltage_t mJoltage; size_t mLeftIndex, mRightIndex; std::vector mEnabledBatteries; }; class Day03Solution : public AdventHelpers::AdventOfCodeSolution { public: virtual std::string SolveProblem01(AdventHelpers::InputFileHelper& inputFile) override { std::vector batteries; unsigned int joltage = 0; for (const auto& line : inputFile) { batteries.push_back(line); } for (const auto& battery : batteries) { battery.printMd(); joltage += battery.joltage(); } return std::to_string(joltage); } virtual std::string SolveProblem02(AdventHelpers::InputFileHelper& inputFile) override { return "todo"; } }; int main() { Day03Solution solution; solution.SolveAll(); return 0; }