aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-22 22:22:23 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-22 22:22:23 +0800
commit7554567d7317f56667d9116ae08ff147d3291475 (patch)
tree1b0f714c1718f728e3735614ebe6ada2b4426849 /src
parentc2dcf1ccfc1c8153e1b8ed0c48783c1edd4ef6aa (diff)
downloadadvent-of-code-7554567d7317f56667d9116ae08ff147d3291475.tar.gz
advent-of-code-7554567d7317f56667d9116ae08ff147d3291475.zip
2016 day14
Diffstat (limited to 'src')
-rw-r--r--src/2016/day14/aoc.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/2016/day14/aoc.cpp b/src/2016/day14/aoc.cpp
index d70ff49..d10d1e0 100644
--- a/src/2016/day14/aoc.cpp
+++ b/src/2016/day14/aoc.cpp
@@ -48,6 +48,14 @@ static bool in_range(char c, size_t l, size_t h) {
return false;
}
+std::string stretching(const char* md5, size_t n) {
+ std::string s{md5};
+ while (n-- > 0) {
+ s = std::string{md5sum((char*)s.c_str()), 32};
+ }
+ return s;
+}
+
md5_property md5(const char* secret, size_t index) {
if (index >= md5s.size()) {
char buf[128] = {0};
@@ -58,6 +66,7 @@ md5_property md5(const char* secret, size_t index) {
for (size_t i = s; i < md5s.size(); i++) {
sprintf(buf + l, "%zu", i);
md5s[i].md5 = std::string(md5sum(buf), 32);
+ // md5s[i].md5 = stretching(md5s[i].md5.c_str(), 2016);
auto pc3 = has(md5s[i].md5.c_str(), 3);
if (pc3 != nullptr) {
md5s[i].c = *pc3;
@@ -80,6 +89,7 @@ size_t find_key(int* count, int max) {
while (*count < max && i < md5s.size()) {
auto& p = md5s[i];
if (p.c > 0 && in_range(p.c, i + 1, i + 1000)) {
+ // printf("%zu %s with %c\n", i, p.md5.c_str(), p.c);
*count += 1;
}
i++;
@@ -89,7 +99,6 @@ size_t find_key(int* count, int max) {
std::pair<size_t, int64_t> day14(line_view) {
// md5("abc", 30000);
-
md5("jlmsuwbz", 50000);
int count{0};
auto i = find_key(&count, 64);