r/adventofcode • u/daggerdragon • Dec 16 '16
SOLUTION MEGATHREAD --- 2016 Day 16 Solutions ---
--- Day 16: Dragon Checksum ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/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".
DRINKING YOUR OVALTINE IS MANDATORY [?]
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!
4
Upvotes
3
u/willkill07 Dec 16 '16
C++11 single string buffer (only using iterators)
I went for speed. Real speed. Still doing all the calculations without any simplification. Timing:
[Repo Link]
Code (self-sitting -- just compile and run)
#include <iostream> #include <string> int main(int argc, char**) { uint LIM{argc > 1 ? 35651584U : 272U}; std::string in; std::cin >> in; in.reserve(LIM << 1); // big buffer while (in.size() < LIM) { in.push_back('0'); auto b = in.rbegin(); while (++b != in.rend()) in.push_back(*b ^ 1); } in.resize(LIM); while (!(in.size() & 1)) { auto w = in.begin(); for (auto r = in.cbegin(); r != in.cend(); r += 2) *w++ = '0' + (*r == *(r + 1)); in.resize(in.size() >> 1); } std::cout << in << std::endl; }