66#include < string>
77
88namespace AdventOfCode24 ::Day7 {
9- long check_calibration_line (const std::string& line, bool include_concatenator, const char & delimiter) {
9+ int64_t check_calibration_line (const std::string& line, bool include_concatenator, const char & delimiter) {
1010 auto divider_find = std::find (line.begin (), line.end (), delimiter);
1111
1212 if (divider_find == line.end ()) {
@@ -20,47 +20,47 @@ namespace AdventOfCode24::Day7 {
2020 throw std::runtime_error (" Target string is empty for line: " + line);
2121 }
2222
23- long target{-1 };
23+ int64_t target{-1 };
2424
2525 try {
2626 target = std::stol (target_str);
2727 } catch (std::exception& e) {
28- throw std::runtime_error (" Could not convert '" + target_str + " ' to long integer." );
28+ throw std::runtime_error (" Could not convert '" + target_str + " ' to int64_t integer." );
2929 }
3030
3131 if (target < 0 ) {
32- throw std::runtime_error (target_str + " exceeds limit of long integer." );
32+ throw std::runtime_error (target_str + " exceeds limit of int64_t integer." );
3333 }
3434
3535 std::istringstream iss;
3636 iss.str (operands);
37- long number{-1 };
37+ int64_t number{-1 };
3838 int n_numbers{0 };
39- std::vector<long > operations{0 };
39+ std::vector<int64_t > operations{0 };
4040
4141 while (iss >> number) {
42- std::vector<long > results;
42+ std::vector<int64_t > results;
4343
4444 n_numbers++;
4545
46- for (const long & n : operations) {
47- const long multiply{((n==0 ) ? 1 : n) * number};
48- const long add{n + number};
46+ for (const int64_t & n : operations) {
47+ const int64_t multiply{((n==0 ) ? 1 : n) * number};
48+ const int64_t add{n + number};
4949
5050 if (multiply < 0 ) {
51- throw std::runtime_error (std::to_string (multiply) + " exceeds limit of long integer." );
51+ throw std::runtime_error (std::to_string (multiply) + " exceeds limit of int64_t integer." );
5252 }
5353
5454 if (add < 0 ) {
55- throw std::runtime_error (std::to_string (add) + " exceeds limit of long integer." );
55+ throw std::runtime_error (std::to_string (add) + " exceeds limit of int64_t integer." );
5656 }
5757
5858 if (multiply <= target) results.push_back (multiply);
5959 if (add <= target) results.push_back (add);
6060
6161 if (include_concatenator) {
6262 const std::string concatenate_str{std::to_string (n) + std::to_string (number)};
63- const long concatenate{std::stol (concatenate_str)};
63+ const int64_t concatenate{std::stol (concatenate_str)};
6464 if (concatenate <= target) results.push_back (concatenate);
6565 }
6666 }
@@ -85,29 +85,28 @@ namespace AdventOfCode24::Day7 {
8585 if (max_loc == operations.end ()) {
8686 spdlog::warn (" Line failed, operation result below target value after processing." );
8787 } else {
88- const long max_reached{*max_loc};
88+ const int64_t max_reached{*max_loc};
8989 spdlog::warn (" Line failed, operation result below target value after processing " + std::to_string (n_numbers) + " : " + std::to_string (max_reached) + " < " + std::to_string (target));
9090 }
9191 return 0 ;
9292 }
9393
94- std::vector<long > process_file (const std::filesystem::path& input_file, bool include_concatenator) {
94+ std::vector<int64_t > process_file (const std::filesystem::path& input_file, bool include_concatenator) {
9595 std::ifstream read_in (input_file, std::ios::in);
9696 std::string line;
97- std::vector<long > calibration_results;
97+ std::vector<int64_t > calibration_results;
9898 int n_lines{0 };
9999
100100 while (std::getline (read_in, line)) {
101101 if (line.empty ()) continue ;
102102
103- const long calibration{check_calibration_line (line, include_concatenator)};
103+ const int64_t calibration{check_calibration_line (line, include_concatenator)};
104104
105105 if (calibration < 0 ) {
106106 throw std::runtime_error (" Tried to append negative value " + std::to_string (calibration) + " to total!" );
107107 }
108108
109109 calibration_results.push_back (calibration);
110- std::cout << calibration << std::endl;
111110
112111 n_lines++;
113112 }
0 commit comments