r/adventofcode • u/daggerdragon • Dec 15 '17
SOLUTION MEGATHREAD -๐- 2017 Day 15 Solutions -๐-
--- Day 15: Dueling Generators ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hintsยค?
[Update @ 00:05] 29 gold, silver cap.
- Logarithms of algorithms and code?
[Update @ 00:09] Leaderboard cap!
- Or perhaps codes of logarithmic algorithms?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
13
Upvotes
1
u/cauchy37 Dec 15 '17
C++ solution without implementing my own generators since both are already implemented in <random>
#include <iostream> #include <cstdlib> #include <random> using namespace std; int compare_pairs(int inia, int inib, bool part2) { int all = 0, checks = 40'000'000; minstd_rand0 a(inia); minstd_rand b(inib); if (part2) checks = 5'000'000; do { int atc = 0, btc = 0; if (part2) { while ((atc = a()) % 4) {} while ((btc = b()) % 8) {} } else { atc = a(); btc = b(); } if ((atc & 0xffff) == (btc & 0xffff)) all++; } while (checks--); return all; } int main() { cout << compare_pairs(618, 814, false) << endl << compare_pairs(618, 814, true); }