-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathday_01a.cpp
More file actions
31 lines (27 loc) · 767 Bytes
/
day_01a.cpp
File metadata and controls
31 lines (27 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
int main(int argc, char* argv[]) {
// Get input
std::string input = "../input/day_01_input";
if (argc > 1) {
input = argv[1];
}
std::ifstream file(input);
std::istream_iterator<int> start(file), end;
const std::vector<int> masses(start, end);
// Solve
long long total_fuel = 0;
constexpr int divisor = 3;
constexpr int subtract = 2;
for (const auto& mass : masses) {
total_fuel += mass / divisor - subtract;
}
// STL variant
// long long total_fuel = std::accumulate(start, end, 0, [](long long
// sum_fuel, const int ele) { return sum_fuel + getRecursiveFuel(ele);} );
std::cout << total_fuel << '\n';
return total_fuel;
}