about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-12-16 23:01:31 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-12-16 23:01:31 +0100
commit302fe6770b1e206964dafc265a38fdda405e61c0 (patch)
treec8674ebf2da5e4bd2dcf03e06497f11ed05ea673
parentf4e01b6401a224fddc3143b15031c6ef60e15efd (diff)
downloadadventofcode2017-302fe6770b1e206964dafc265a38fdda405e61c0.tar.gz
adventofcode2017-302fe6770b1e206964dafc265a38fdda405e61c0.tar.xz
adventofcode2017-302fe6770b1e206964dafc265a38fdda405e61c0.zip
day15
-rw-r--r--day152
-rw-r--r--day15.cc29
-rw-r--r--day15.k18
3 files changed, 49 insertions, 0 deletions
diff --git a/day15 b/day15
new file mode 100644
index 0000000..23c8ba4
--- /dev/null
+++ b/day15
@@ -0,0 +1,2 @@
+Generator A starts with 634
+Generator B starts with 301
diff --git a/day15.cc b/day15.cc
new file mode 100644
index 0000000..55a3d6d
--- /dev/null
+++ b/day15.cc
@@ -0,0 +1,29 @@
+#include <iostream>
+
+using namespace std;
+
+template <int const n=0>
+struct lrng {
+	uint64_t m, s;
+	uint16_t operator*() const { return s; }
+	auto operator++() { do s = s * m % 2147483647; while (n && s % n != 0); }
+};
+
+int
+main() {
+	int p1{0}, p2{0};
+
+	lrng<> a1{16807, 634};
+	lrng<> b1{48271, 301};
+	for (long i{0}; i < 40'000'000; ++i, ++a1, ++b1)
+		if (*a1 == *b1)
+			p1++;
+
+	lrng<4> a2{16807, 634};
+	lrng<8> b2{48271, 301};
+	for (long i{0}; i < 5'000'000; ++i, ++a2, ++b2)
+		if (*a2 == *b2)
+			p2++;
+
+	cout << p1 << endl << p2 << endl;	// 573 294
+}
diff --git a/day15.k b/day15.k
new file mode 100644
index 0000000..063c739
--- /dev/null
+++ b/day15.k
@@ -0,0 +1,18 @@
+a:634
+b:301
+
+n:40000000
+
+u:65536!n{2147483647!16807*x}\a
+v:65536!n{2147483647!48271*x}\b
++/u=v		/ 573
+
+/ +/=/'65536!40000000(2147483647!16807 48271*)\634,301   slower
+
+n:5000000
+
+u:{~4!x}#65536!(4*n){2147483647!16807*x}\a
+v:{~8!x}#65536!(8*n+4000){2147483647!48271*x}\b
++/(n#u)=(n#v)  / 294
+
+\\