-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (48 loc) · 1.65 KB
/
main.cpp
File metadata and controls
59 lines (48 loc) · 1.65 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <chrono>
#include <regex>
#include "../Utils/utils.h"
#include "../Utils/Vector.h"
void solvePuzzle(const std::vector<std::string>& puzzle, int stage){
std::vector<size_t> lifetimes;
aoc_utils::splitString(puzzle.at(0), ',', lifetimes);
std::array<size_t, 9> fishPerDay = {0};
for(auto& time : lifetimes){
fishPerDay[time]++;
}
for(int i = 0; i < (stage == 1 ? 80 : 256); i++){
size_t zero = fishPerDay[0];
for(int j = 1; j < 9; j++){
fishPerDay[j-1] = fishPerDay[j];
}
fishPerDay[6] += zero;
fishPerDay[8] = zero; // that many fish are born this day;
}
size_t totalFishes = 0;
for(int i = 0; i < 9; i++){
totalFishes += fishPerDay[i];
}
std::cout << totalFishes << "\n";
}
void stage1(const std::vector<std::string>& puzzle){
solvePuzzle(puzzle, 1);
}
void stage2(const std::vector<std::string>& puzzle){
solvePuzzle(puzzle, 2);
}
int main(){
std::vector<std::string> puzzle;
std::string input = "example";
input = "input";
aoc_utils::load_puzzle(input, puzzle);
auto start = std::chrono::high_resolution_clock::now();
stage1(puzzle);
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = end - start;
std::cout << "Stage 1 took " << elapsed.count() << " seconds\n";
start = std::chrono::high_resolution_clock::now();
stage2(puzzle);
end = std::chrono::high_resolution_clock::now();
elapsed = end - start;
std::cout << "Stage 2 took " << elapsed.count() << " seconds\n";
}