diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-03-15 19:18:51 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-03-15 19:18:51 +0800 |
commit | 26c12eccc385caf773f1fcbfc3da560559022aaf (patch) | |
tree | 4172a552e24139fb036135bb8c8d1203f22c1c5d /src/2015/day4/aoc.cpp | |
parent | 035a612de50f7d36fdbef0d1aee3b31f5fef4596 (diff) | |
download | advent-of-code-26c12eccc385caf773f1fcbfc3da560559022aaf.tar.gz advent-of-code-26c12eccc385caf773f1fcbfc3da560559022aaf.zip |
day4
Diffstat (limited to 'src/2015/day4/aoc.cpp')
-rw-r--r-- | src/2015/day4/aoc.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/2015/day4/aoc.cpp b/src/2015/day4/aoc.cpp index 1bb0d4e..ab5f301 100644 --- a/src/2015/day4/aoc.cpp +++ b/src/2015/day4/aoc.cpp @@ -27,4 +27,19 @@ int lead_zeros(char* s) { return total; } +int day4(const char* secret, int target) { + char buf[128] = {0}; + int len = strlen(secret); + memcpy(buf, secret, len); + int i = 1; + while (i < INT32_MAX) { + sprintf(buf+len, "%d", i); + if (lead_zeros(md5sum(buf)) >= target) { + break; + } + i++; + } + return i; +} + } // namespace aoc2015 |