blob: 34693dfd9589e0abbecac7b62716220833c6c6ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#include "aoc.h"
namespace aoc2015 {
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
|