-
Notifications
You must be signed in to change notification settings - Fork 0
/
06.cpp
39 lines (33 loc) · 873 Bytes
/
06.cpp
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
32
33
34
35
36
37
38
39
#include <iostream>
#include <fstream>
#include <string>
#include <array>
using FishMap = std::array<long long, 9>;
void solve(FishMap& fish, int days) {
for (int i = 0; i < days; ++i) {
long long newFish = 0;
for (int j = 0; j < fish.size(); ++j) {
if (j == 0) newFish = fish[j];
else fish[j - 1] = fish[j];
fish[j] = 0;
}
fish[6] += newFish;
fish[8] = newFish;
}
long long sum = 0;
for (auto&& x: fish) sum += x;
std::cout << sum << std::endl;
}
int main(int argc, char* argv[]) {
std::ifstream dataFile(argv[1]);
FishMap fish{ 0, 0, 0, 0, 0, 0, 0, 0, 0 };
std::string num;
while (std::getline(dataFile, num, ',')) {
++fish[std::stoi(num)];
}
dataFile.close();
// partOne
//solve(fish, 80);
// partTwo
solve(fish, 256);
}