about summary refs log tree commit diff
path: root/day13.cc
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-12-14 17:24:52 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-12-14 17:24:52 +0100
commit84e0e9d9e382344e36103c36cb9b47137a75e7d3 (patch)
tree59f22541ff386b8667d8f080793df5e51dc152db /day13.cc
parent777766e6cf7b8c9851b4015e9691a038d3b5808b (diff)
downloadadventofcode2017-84e0e9d9e382344e36103c36cb9b47137a75e7d3.tar.gz
adventofcode2017-84e0e9d9e382344e36103c36cb9b47137a75e7d3.tar.xz
adventofcode2017-84e0e9d9e382344e36103c36cb9b47137a75e7d3.zip
day13
Diffstat (limited to 'day13.cc')
-rw-r--r--day13.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/day13.cc b/day13.cc
new file mode 100644
index 0000000..91fb5c6
--- /dev/null
+++ b/day13.cc
@@ -0,0 +1,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;
+		}
+}