about summary refs log tree commit diff
path: root/day13.cc
blob: 91fb5c66a49d0c6a39cc83c86c50c971e1c7d005 (plain) (blame)
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
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using namespace std::placeholders;

struct scanner {
	int d, r;
	bool hit(int delay=0) { return (d + delay) % (2*r - 2) == 0; }
	operator int() { return hit() ? d * r : 0; }
};

int main()
{
	vector<scanner> ss;
	char _;
	for (int d, r; cin >> d >> _ >> r; )
		ss.push_back({d, r});

	cout << std::accumulate(begin(ss), end(ss), 0) << endl;

	for (int d = 0; ; d++)
		if (none_of(ss.begin(), ss.end(), bind(&scanner::hit, _1, d))) {
			cout << d << endl;
			break;
		}
}