about summary refs log tree commit diff
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
parent777766e6cf7b8c9851b4015e9691a038d3b5808b (diff)
downloadadventofcode2017-84e0e9d9e382344e36103c36cb9b47137a75e7d3.tar.gz
adventofcode2017-84e0e9d9e382344e36103c36cb9b47137a75e7d3.tar.xz
adventofcode2017-84e0e9d9e382344e36103c36cb9b47137a75e7d3.zip
day13
-rw-r--r--day1344
-rw-r--r--day13.cc30
-rw-r--r--day13.k4
3 files changed, 78 insertions, 0 deletions
diff --git a/day13 b/day13
new file mode 100644
index 0000000..701ff7f
--- /dev/null
+++ b/day13
@@ -0,0 +1,44 @@
+0: 3
+1: 2
+2: 6
+4: 4
+6: 4
+8: 10
+10: 6
+12: 8
+14: 5
+16: 6
+18: 8
+20: 8
+22: 12
+24: 6
+26: 9
+28: 8
+30: 8
+32: 10
+34: 12
+36: 12
+38: 8
+40: 12
+42: 12
+44: 14
+46: 12
+48: 12
+50: 12
+52: 12
+54: 14
+56: 14
+58: 14
+60: 12
+62: 14
+64: 14
+66: 17
+68: 14
+72: 18
+74: 14
+76: 20
+78: 14
+82: 18
+86: 14
+90: 18
+92: 14
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;
+		}
+}
diff --git a/day13.k b/day13.k
new file mode 100644
index 0000000..8f0aacf
--- /dev/null
+++ b/day13.k
@@ -0,0 +1,4 @@
+n:.-2+2*m:!/.:''+":"\'0:`day13
+
++/s*m@s:k@&0=n!'k:!m	/ 3184
+{~*/n!'x+k}(1+)/1	/ 3878062, slow