aboutsummaryrefslogtreecommitdiff
path: root/src/2016/day5/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-04-10 14:56:42 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-04-10 14:56:42 +0800
commitfd91857910e637f6d813a19b745df7808b9b25af (patch)
tree435ce0ffd5deac7cdebb758610f833740af3297c /src/2016/day5/aoc.cpp
parentd4d515b2159dd50b76da060bfa11337bca04feed (diff)
downloadadvent-of-code-fd91857910e637f6d813a19b745df7808b9b25af.tar.gz
advent-of-code-fd91857910e637f6d813a19b745df7808b9b25af.zip
2016 day5
Diffstat (limited to 'src/2016/day5/aoc.cpp')
-rw-r--r--src/2016/day5/aoc.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/2016/day5/aoc.cpp b/src/2016/day5/aoc.cpp
index 55f4247..16c5f70 100644
--- a/src/2016/day5/aoc.cpp
+++ b/src/2016/day5/aoc.cpp
@@ -1,5 +1,32 @@
#include "aoc.h"
+#include "md5.h"
+#include <string.h>
namespace aoc2016 {
+void day5(const char* secret, int len, char pass1[], char pass2[]) {
+ char buf[128] = {0};
+ int l = strlen(secret);
+ memcpy(buf, secret, len);
+ int64_t i = 0;
+ int x1 = len;
+ int x2 = 0;
+ while (i < INT64_MAX && x2 < 8) {
+ sprintf(buf + l, "%zu", i);
+ char* hash = md5sum(buf);
+ if (lead_zeros(hash) >= 5) {
+ printf("%zu %s\n", i, hash);
+ if (x1 > 0) {
+ pass1[len - x1] = hash[5];
+ x1--;
+ }
+ if (hash[5] >= '0' && hash[5] <= '7' && pass2[hash[5] - '0'] == '\0') {
+ pass2[hash[5] - '0'] = hash[6];
+ x2 += 1;
+ }
+ }
+ i++;
+ }
}
+
+} // namespace aoc2016