about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-12-11 17:27:35 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-12-11 17:27:35 +0100
commitbc3f64835aca551f54cf2b2df86200d991b97a07 (patch)
treeea9f36bad7c9beb0a6fc32353ae671af3d1add8d
parent695421801592cb53d69ca4e7dbab9ab1a0120edd (diff)
downloadadventofcode2017-bc3f64835aca551f54cf2b2df86200d991b97a07.tar.gz
adventofcode2017-bc3f64835aca551f54cf2b2df86200d991b97a07.tar.xz
adventofcode2017-bc3f64835aca551f54cf2b2df86200d991b97a07.zip
day10
-rw-r--r--day101
-rw-r--r--day10.cc56
-rw-r--r--day10.k12
3 files changed, 69 insertions, 0 deletions
diff --git a/day10 b/day10
new file mode 100644
index 0000000..2fd89cf
--- /dev/null
+++ b/day10
@@ -0,0 +1 @@
+106,16,254,226,55,2,1,166,177,247,93,0,255,228,60,36
diff --git a/day10.cc b/day10.cc
new file mode 100644
index 0000000..c260487
--- /dev/null
+++ b/day10.cc
@@ -0,0 +1,56 @@
+#include <algorithm>
+#include <iomanip>
+#include <iterator>
+#include <iostream>
+#include <numeric>
+#include <sstream>
+#include <string>
+#include <vector>
+
+using namespace std;
+
+struct CommaInts : string {
+	friend istream& operator>>(istream& is, CommaInts& line) {
+		return getline(is, line, ',');
+	}
+	operator int() const { return stoi(*this); }
+};
+auto begin(istream_iterator<CommaInts>& l) { return l; }
+auto end(istream_iterator<CommaInts>&) { return istream_iterator<CommaInts>{}; }
+
+template <typename T>
+auto knothash(T iter, int n)
+{
+	vector<int> v(256);
+	iota(begin(v), end(v), 0);
+
+	uint8_t skip = 0, pos = 0, delta;
+
+	for (int j = 0; j < n; j++)
+		for (auto i : iter) {
+			reverse(begin(v), begin(v) + i);
+			delta = i + skip++;
+			rotate(begin(v), begin(v) + delta, end(v));
+			pos += delta;
+		}
+	rotate(begin(v), end(v) - pos, end(v));
+
+	return move(v);
+}
+
+int
+main() {
+	string line;
+	cin >> line;
+
+	istringstream iss{line};
+	vector<int> v1{knothash(istream_iterator<CommaInts>(iss), 1)};
+	cout << v1[0] * v1[1] << endl;
+
+	line.append({17,31,73,47,23});
+	vector<int> v2{knothash(line, 64)};
+	for (auto b = begin(v2); b != end(v2); advance(b, 16))
+		cout << setfill('0') << setw(2) << hex <<
+		    accumulate(b, b + 16, 0, bit_xor<uint8_t>());
+	cout << endl;
+}
diff --git a/day10.k b/day10.k
new file mode 100644
index 0000000..c568281
--- /dev/null
+++ b/day10.k
@@ -0,0 +1,12 @@
+d:*0:`day10
+S:256
+k:{(S#(S-m)_v,v:(|y#r),y_r:S#(m:S!x 1)_h,h:*x;+/y,x 1 2;1+x 2)}
+
+*/2#*(!S;0;0)k/. d	/ 11413
+
+1 k/[;0+d,17 31 73 47 23]/(!S;0;0)
+
+`c$,/+S\(2/2!+/+2\)'16 0N#*64 k/[;0+d,17 31 73 47 23]/(!S;0;0)
+			/ 7adfd64c2a03a4968cf708d1b7fd418d
+
+/\\