-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
37 lines (32 loc) · 773 Bytes
/
main.cpp
File metadata and controls
37 lines (32 loc) · 773 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
32
33
34
35
36
37
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_set>
using namespace std;
int main() {
ifstream fileName("advent1.txt");
string in;
vector<int> changes;
int total = 0;
while (getline(fileName, in)) {
int number = stol(in);
changes.push_back(number);
total += number;
}
cout << "p1: " << total << std::endl;
unordered_set<int> set;
set.insert(0);
int total2 = 0;
while (true) {
for (int number : changes) {
total2 += number;
if (set.find(total2) == set.end()) {
set.insert(total2);
} else {
cout << "p2: " << total2 << endl;
return 0;
}
}
}
return 0;
}