diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-16 23:01:31 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-16 23:01:31 +0100 |
commit | 302fe6770b1e206964dafc265a38fdda405e61c0 (patch) | |
tree | c8674ebf2da5e4bd2dcf03e06497f11ed05ea673 /day15.cc | |
parent | f4e01b6401a224fddc3143b15031c6ef60e15efd (diff) | |
download | adventofcode2017-302fe6770b1e206964dafc265a38fdda405e61c0.tar.gz adventofcode2017-302fe6770b1e206964dafc265a38fdda405e61c0.tar.xz adventofcode2017-302fe6770b1e206964dafc265a38fdda405e61c0.zip |
day15
Diffstat (limited to 'day15.cc')
-rw-r--r-- | day15.cc | 29 |
1 files changed, 29 insertions, 0 deletions
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 +} |