mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Solutions to day 1 2017.
This commit is contained in:
29
2017/day-01/solution.cpp
Normal file
29
2017/day-01/solution.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <cctype>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void get_sum(const string& data, const unsigned int offset)
|
||||
{
|
||||
int sum = 0;
|
||||
const auto total = data.size();
|
||||
for (auto i = 0u; i < total; ++i) {
|
||||
if (data[i] == data[(i + offset) % total]) {
|
||||
sum += data[i] - '0';
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Sum: " << sum << endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
string data;
|
||||
cin >> data;
|
||||
|
||||
get_sum(data, 1);
|
||||
get_sum(data, data.size() / 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user