Added older advents

This commit is contained in:
Jos van Goor 2022-12-01 13:46:47 +01:00
parent 8db2505049
commit 9cf858b860
78 changed files with 13807 additions and 0 deletions

View file

@ -0,0 +1,46 @@
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int read()
{
string line;
getline(cin, line);
bool plus = line[0] == '+';
int val = stoi(line.substr(1));
return plus ? val : -val;
}
int main()
{
vector<int> sequence;
while (!cin.eof())
sequence.push_back(read());
// cout << "Buffered " << sequence.size() << " frequencies\n";
int total = 0;
set<int> used;
used.insert(0);
while (true)
{
for (int i : sequence)
{
total += i;
if (used.find(total) != used.end())
{
cout << "Found first repeating frequency: " << total << "\n";
return 0;
}
used.insert(total);
}
}
}