Skip to content

Instantly share code, notes, and snippets.

@willkill07
Created December 16, 2016 21:29
Show Gist options
  • Save willkill07/31eff033ef25b1b38311fd3f220037c8 to your computer and use it in GitHub Desktop.
Save willkill07/31eff033ef25b1b38311fd3f220037c8 to your computer and use it in GitHub Desktop.
Day16.cpp
#include <chrono>
#include <iostream>
#include <string>
int main(int argc, char**) {
auto start = std::chrono::high_resolution_clock::now();
uint LIM{argc > 1 ? 35651584U : 272U};
std::string in;
in.reserve(LIM << 1); // big buffer
std::cin >> in;
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);
}
auto stop = std::chrono::high_resolution_clock::now();
std::cout << in << std::endl;
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count() << " microseconds" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment