Compare commits
5 Commits
adf2565729
...
68ce9ca703
Author | SHA1 | Date |
---|---|---|
Benjamin Kraft | 68ce9ca703 | 2 years ago |
Benjamin Kraft | 38cb42bfee | 2 years ago |
Benjamin Kraft | 0b4b4590c0 | 2 years ago |
Benjamin Kraft | af9edbcca1 | 2 years ago |
Benjamin Kraft | 17079b5542 | 2 years ago |
6 changed files with 29 additions and 8 deletions
@ -1,9 +1,24 @@ |
|||||||
#include "Day01.h" |
#include "Day01.h" |
||||||
|
|
||||||
Result Day01::Task1() { |
Result Day01::Task1() { |
||||||
return Day::Task1(); |
subSums.push_back(0); |
||||||
|
for (const std::string& line : input){ |
||||||
|
if (line.empty()) |
||||||
|
subSums.push_back(0); |
||||||
|
else |
||||||
|
subSums[subSums.size() - 1] += stoi(line); |
||||||
|
} |
||||||
|
return to_string(*std::max_element(subSums.begin(), subSums.end())); |
||||||
} |
} |
||||||
|
|
||||||
Result Day01::Task2() { |
Result Day01::Task2() { |
||||||
return Day::Task2(); |
std::sort(subSums.begin(), subSums.end()); |
||||||
|
|
||||||
|
int sum = 0; |
||||||
|
for (int i = 0; i < 3; i++){ |
||||||
|
sum += subSums.back(); |
||||||
|
subSums.pop_back(); |
||||||
|
} |
||||||
|
|
||||||
|
return to_string(sum); |
||||||
} |
} |
Loading…
Reference in new issue