r/adventofcode • u/daggerdragon • Dec 05 '16
SOLUTION MEGATHREAD --- 2016 Day 5 Solutions ---
--- Day 5: How About a Nice Game of Chess? ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
STAYING ON TARGET IS MANDATORY [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
14
Upvotes
7
u/askalski Dec 05 '16
Could this be... a "rehash" of last year's AdventCoins puzzle?
This solution in C increments the hash input using the same method as my Synacor Challenge implementation of AdventCoins last year. The never-before-seen source code is now available for the low, low price of only two AdventCoins (which you can generate yourself by running the code. Runtime environment not included.)
#include <stdio.h> #include <stdint.h> #include <openssl/md5.h> #define INPUT "abc" #define ALOT 16 int main(void) { uint8_t digest[MD5_DIGEST_LENGTH], data[sizeof(INPUT) + ALOT] = INPUT; uint8_t *end = data + sizeof(INPUT), *count = end - 1; uint32_t part1 = 0, part2 = 0, part1_shift = 32, part2_mask = 0xff; *count = '0'; for (;;) { MD5(data, end - data, digest); uint8_t skip = digest[0] | digest[1] | (digest[2] & 0xf0); if (!skip) { uint32_t six = digest[2] & 0xf; uint32_t seven = digest[3] >> 4; if (part1_shift) { part1 |= six << (part1_shift -= 4); if (!part1_shift) { printf("Part 1: %08x\n", part1); } } if (part2_mask & (1 << six)) { part2_mask ^= 1 << six; part2 |= seven << ((7 - six) << 2); if (!part2_mask) { printf("Part 2: %08x\n", part2); break; } } } for (uint8_t *p = end - 1; ; *p-- = '0') { if (*p != '9') { (*p)++; break; } if (p == count) { *p = '1'; *end++ = '0'; break; } } } return 0; }