diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-01-22 20:35:49 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-01-22 20:35:49 +0800 |
commit | c2dcf1ccfc1c8153e1b8ed0c48783c1edd4ef6aa (patch) | |
tree | 6013053b1b18d50b3fadb47eec859c8a1cf91baa /src/2016/day14/aoc.cpp | |
parent | c0de24475bcb8231d951ca894c3717ec4aa3080a (diff) | |
download | advent-of-code-c2dcf1ccfc1c8153e1b8ed0c48783c1edd4ef6aa.tar.gz advent-of-code-c2dcf1ccfc1c8153e1b8ed0c48783c1edd4ef6aa.zip |
2016 day14 part1
Diffstat (limited to 'src/2016/day14/aoc.cpp')
-rw-r--r-- | src/2016/day14/aoc.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/2016/day14/aoc.cpp b/src/2016/day14/aoc.cpp index 364bb5e..d70ff49 100644 --- a/src/2016/day14/aoc.cpp +++ b/src/2016/day14/aoc.cpp @@ -56,16 +56,17 @@ md5_property md5(const char* secret, size_t index) { auto s = md5s.size(); md5s.resize(index + 1); for (size_t i = s; i < md5s.size(); i++) { - sprintf(buf + l, "%zu", index); + sprintf(buf + l, "%zu", i); md5s[i].md5 = std::string(md5sum(buf), 32); auto pc3 = has(md5s[i].md5.c_str(), 3); if (pc3 != nullptr) { md5s[i].c = *pc3; auto pc5 = has(md5s[i].md5.c_str(), 5); if (pc5 != nullptr) { - auto p = has5s.insert({*pc3, {index}}); + // printf("%zu has 5 %c\n", i, *pc3); + auto p = has5s.insert({*pc3, {i}}); if (!p.second) { - p.first->second.push_back(index); + p.first->second.push_back(i); } } } @@ -83,15 +84,15 @@ size_t find_key(int* count, int max) { } i++; } - return i; + return i - 1; } -std::pair<int64_t, int64_t> day14(line_view) { - md5("abc", 30000); - // md5("jlmsuwbz", 30000); +std::pair<size_t, int64_t> day14(line_view) { + // md5("abc", 30000); + + md5("jlmsuwbz", 50000); int count{0}; auto i = find_key(&count, 64); - printf("%zu\n", i); - return {0, 0}; + return {i, 0}; } } // namespace aoc2016 |