2016 / Day 17
Two Steps Forward
Read the original puzzle on adventofcode.com ↗
The solution
solution.c
1#include "aoc.h"
2
3/* Passcode <= 64 bytes, path depth <= 1024, at most 200000 room visits.
4 * Rooms are path-dependent: revisiting a coordinate cannot be deduplicated.
5 * Iterative DFS keeps one incremental MD5 context per path prefix in static
6 * storage. Part 1 prunes paths at the shortest known length. */
7enum { DEPTH = 1024, VISITS = 200000 };
8
9#define MD5ROL(x, s) (((x) << (s)) | ((x) >> (32 - (s))))
10#define MD5F(x, y, z) (((x) & (y)) | (~(x) & (z)))
11#define MD5G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
12#define MD5H(x, y, z) ((x) ^ (y) ^ (z))
13#define MD5I(x, y, z) ((y) ^ ((x) | ~(z)))
14#define MD5STEP(fn, a, b, c, d, x, s, k) \
15 a = b + MD5ROL(a + fn(b, c, d) + (x) + (uint32_t)(k), (s))
16
17static void md5_block(uint32_t st[4], const uint8_t *blk) {
18 uint32_t w[16];
19 uint32_t A = st[0], B = st[1], C = st[2], D = st[3];
20
21 w[0] = (uint32_t)blk[0] | ((uint32_t)blk[1] << 8) |
22 ((uint32_t)blk[2] << 16) | ((uint32_t)blk[3] << 24);
23 w[1] = (uint32_t)blk[4] | ((uint32_t)blk[5] << 8) |
24 ((uint32_t)blk[6] << 16) | ((uint32_t)blk[7] << 24);
25 w[2] = (uint32_t)blk[8] | ((uint32_t)blk[9] << 8) |
26 ((uint32_t)blk[10] << 16) | ((uint32_t)blk[11] << 24);
27 w[3] = (uint32_t)blk[12] | ((uint32_t)blk[13] << 8) |
28 ((uint32_t)blk[14] << 16) | ((uint32_t)blk[15] << 24);
29 w[4] = (uint32_t)blk[16] | ((uint32_t)blk[17] << 8) |
30 ((uint32_t)blk[18] << 16) | ((uint32_t)blk[19] << 24);
31 w[5] = (uint32_t)blk[20] | ((uint32_t)blk[21] << 8) |
32 ((uint32_t)blk[22] << 16) | ((uint32_t)blk[23] << 24);
33 w[6] = (uint32_t)blk[24] | ((uint32_t)blk[25] << 8) |
34 ((uint32_t)blk[26] << 16) | ((uint32_t)blk[27] << 24);
35 w[7] = (uint32_t)blk[28] | ((uint32_t)blk[29] << 8) |
36 ((uint32_t)blk[30] << 16) | ((uint32_t)blk[31] << 24);
37 w[8] = (uint32_t)blk[32] | ((uint32_t)blk[33] << 8) |
38 ((uint32_t)blk[34] << 16) | ((uint32_t)blk[35] << 24);
39 w[9] = (uint32_t)blk[36] | ((uint32_t)blk[37] << 8) |
40 ((uint32_t)blk[38] << 16) | ((uint32_t)blk[39] << 24);
41 w[10] = (uint32_t)blk[40] | ((uint32_t)blk[41] << 8) |
42 ((uint32_t)blk[42] << 16) | ((uint32_t)blk[43] << 24);
43 w[11] = (uint32_t)blk[44] | ((uint32_t)blk[45] << 8) |
44 ((uint32_t)blk[46] << 16) | ((uint32_t)blk[47] << 24);
45 w[12] = (uint32_t)blk[48] | ((uint32_t)blk[49] << 8) |
46 ((uint32_t)blk[50] << 16) | ((uint32_t)blk[51] << 24);
47 w[13] = (uint32_t)blk[52] | ((uint32_t)blk[53] << 8) |
48 ((uint32_t)blk[54] << 16) | ((uint32_t)blk[55] << 24);
49 w[14] = (uint32_t)blk[56] | ((uint32_t)blk[57] << 8) |
50 ((uint32_t)blk[58] << 16) | ((uint32_t)blk[59] << 24);
51 w[15] = (uint32_t)blk[60] | ((uint32_t)blk[61] << 8) |
52 ((uint32_t)blk[62] << 16) | ((uint32_t)blk[63] << 24);
53 MD5STEP(MD5F, A, B, C, D, w[0], 7, 0xd76aa478u);
54 MD5STEP(MD5F, D, A, B, C, w[1], 12, 0xe8c7b756u);
55 MD5STEP(MD5F, C, D, A, B, w[2], 17, 0x242070dbu);
56 MD5STEP(MD5F, B, C, D, A, w[3], 22, 0xc1bdceeeu);
57 MD5STEP(MD5F, A, B, C, D, w[4], 7, 0xf57c0fafu);
58 MD5STEP(MD5F, D, A, B, C, w[5], 12, 0x4787c62au);
59 MD5STEP(MD5F, C, D, A, B, w[6], 17, 0xa8304613u);
60 MD5STEP(MD5F, B, C, D, A, w[7], 22, 0xfd469501u);
61 MD5STEP(MD5F, A, B, C, D, w[8], 7, 0x698098d8u);
62 MD5STEP(MD5F, D, A, B, C, w[9], 12, 0x8b44f7afu);
63 MD5STEP(MD5F, C, D, A, B, w[10], 17, 0xffff5bb1u);
64 MD5STEP(MD5F, B, C, D, A, w[11], 22, 0x895cd7beu);
65 MD5STEP(MD5F, A, B, C, D, w[12], 7, 0x6b901122u);
66 MD5STEP(MD5F, D, A, B, C, w[13], 12, 0xfd987193u);
67 MD5STEP(MD5F, C, D, A, B, w[14], 17, 0xa679438eu);
68 MD5STEP(MD5F, B, C, D, A, w[15], 22, 0x49b40821u);
69 MD5STEP(MD5G, A, B, C, D, w[1], 5, 0xf61e2562u);
70 MD5STEP(MD5G, D, A, B, C, w[6], 9, 0xc040b340u);
71 MD5STEP(MD5G, C, D, A, B, w[11], 14, 0x265e5a51u);
72 MD5STEP(MD5G, B, C, D, A, w[0], 20, 0xe9b6c7aau);
73 MD5STEP(MD5G, A, B, C, D, w[5], 5, 0xd62f105du);
74 MD5STEP(MD5G, D, A, B, C, w[10], 9, 0x02441453u);
75 MD5STEP(MD5G, C, D, A, B, w[15], 14, 0xd8a1e681u);
76 MD5STEP(MD5G, B, C, D, A, w[4], 20, 0xe7d3fbc8u);
77 MD5STEP(MD5G, A, B, C, D, w[9], 5, 0x21e1cde6u);
78 MD5STEP(MD5G, D, A, B, C, w[14], 9, 0xc33707d6u);
79 MD5STEP(MD5G, C, D, A, B, w[3], 14, 0xf4d50d87u);
80 MD5STEP(MD5G, B, C, D, A, w[8], 20, 0x455a14edu);
81 MD5STEP(MD5G, A, B, C, D, w[13], 5, 0xa9e3e905u);
82 MD5STEP(MD5G, D, A, B, C, w[2], 9, 0xfcefa3f8u);
83 MD5STEP(MD5G, C, D, A, B, w[7], 14, 0x676f02d9u);
84 MD5STEP(MD5G, B, C, D, A, w[12], 20, 0x8d2a4c8au);
85 MD5STEP(MD5H, A, B, C, D, w[5], 4, 0xfffa3942u);
86 MD5STEP(MD5H, D, A, B, C, w[8], 11, 0x8771f681u);
87 MD5STEP(MD5H, C, D, A, B, w[11], 16, 0x6d9d6122u);
88 MD5STEP(MD5H, B, C, D, A, w[14], 23, 0xfde5380cu);
89 MD5STEP(MD5H, A, B, C, D, w[1], 4, 0xa4beea44u);
90 MD5STEP(MD5H, D, A, B, C, w[4], 11, 0x4bdecfa9u);
91 MD5STEP(MD5H, C, D, A, B, w[7], 16, 0xf6bb4b60u);
92 MD5STEP(MD5H, B, C, D, A, w[10], 23, 0xbebfbc70u);
93 MD5STEP(MD5H, A, B, C, D, w[13], 4, 0x289b7ec6u);
94 MD5STEP(MD5H, D, A, B, C, w[0], 11, 0xeaa127fau);
95 MD5STEP(MD5H, C, D, A, B, w[3], 16, 0xd4ef3085u);
96 MD5STEP(MD5H, B, C, D, A, w[6], 23, 0x04881d05u);
97 MD5STEP(MD5H, A, B, C, D, w[9], 4, 0xd9d4d039u);
98 MD5STEP(MD5H, D, A, B, C, w[12], 11, 0xe6db99e5u);
99 MD5STEP(MD5H, C, D, A, B, w[15], 16, 0x1fa27cf8u);
100 MD5STEP(MD5H, B, C, D, A, w[2], 23, 0xc4ac5665u);
101 MD5STEP(MD5I, A, B, C, D, w[0], 6, 0xf4292244u);
102 MD5STEP(MD5I, D, A, B, C, w[7], 10, 0x432aff97u);
103 MD5STEP(MD5I, C, D, A, B, w[14], 15, 0xab9423a7u);
104 MD5STEP(MD5I, B, C, D, A, w[5], 21, 0xfc93a039u);
105 MD5STEP(MD5I, A, B, C, D, w[12], 6, 0x655b59c3u);
106 MD5STEP(MD5I, D, A, B, C, w[3], 10, 0x8f0ccc92u);
107 MD5STEP(MD5I, C, D, A, B, w[10], 15, 0xffeff47du);
108 MD5STEP(MD5I, B, C, D, A, w[1], 21, 0x85845dd1u);
109 MD5STEP(MD5I, A, B, C, D, w[8], 6, 0x6fa87e4fu);
110 MD5STEP(MD5I, D, A, B, C, w[15], 10, 0xfe2ce6e0u);
111 MD5STEP(MD5I, C, D, A, B, w[6], 15, 0xa3014314u);
112 MD5STEP(MD5I, B, C, D, A, w[13], 21, 0x4e0811a1u);
113 MD5STEP(MD5I, A, B, C, D, w[4], 6, 0xf7537e82u);
114 MD5STEP(MD5I, D, A, B, C, w[11], 10, 0xbd3af235u);
115 MD5STEP(MD5I, C, D, A, B, w[2], 15, 0x2ad7d2bbu);
116 MD5STEP(MD5I, B, C, D, A, w[9], 21, 0xeb86d391u);
117
118 st[0] += A;
119 st[1] += B;
120 st[2] += C;
121 st[3] += D;
122}
123
124struct hash {
125 uint32_t st[4];
126 uint8_t block[64];
127 size_t len;
128};
129
130struct frame {
131 struct hash hash;
132 uint8_t x, y, doors, next;
133};
134static struct frame stack_[DEPTH + 1];
135static char path_[DEPTH], shortest[DEPTH];
136
137static void feed(struct hash *h, uint8_t c) {
138 h->block[h->len % 64] = c;
139 h->len++;
140 if (!(h->len % 64)) {
141 md5_block(h->st, h->block);
142 }
143}
144
145static uint32_t digest(struct hash h) {
146 size_t n = h.len % 64;
147 uint64_t bits = (uint64_t)h.len * 8;
148 h.block[n++] = 128;
149 if (n > 56) {
150 memset(h.block + n, 0, 64 - n);
151 md5_block(h.st, h.block);
152 n = 0;
153 }
154 memset(h.block + n, 0, 56 - n);
155 for (int k = 0; k < 8; k++) {
156 h.block[56 + k] = (uint8_t)(bits >> (8 * k));
157 }
158 md5_block(h.st, h.block);
159 return h.st[0];
160}
161
162static size_t load(slice in) {
163 size_t n = in.l;
164 if (n && in.p[n - 1] == '\n') {
165 n--;
166 }
167 if (n && in.p[n - 1] == '\r') {
168 n--;
169 }
170 aoc_assert(n && n <= 64, "bad passcode length");
171 for (size_t k = 0; k < n; k++) {
172 aoc_assert((in.p[k] >= 'a' && in.p[k] <= 'z') ||
173 (in.p[k] >= '0' && in.p[k] <= '9'),
174 "bad passcode");
175 }
176 return n;
177}
178
179static slice solve(slice in, int longest) {
180 size_t n = load(in);
181 struct frame *first = stack_;
182 memset(first, 0, sizeof *first);
183 first->hash.st[0] = 0x67452301u;
184 first->hash.st[1] = 0xefcdab89u;
185 first->hash.st[2] = 0x98badcfeu;
186 first->hash.st[3] = 0x10325476u;
187 for (size_t k = 0; k < n; k++) {
188 feed(&first->hash, in.p[k]);
189 }
190 int depth = 0, visits = 0, best = longest ? -1 : DEPTH + 1;
191 static const int8_t dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
192 static const char directions[] = "UDLR";
193 while (depth >= 0) {
194 struct frame *f = stack_ + depth;
195 if (!f->next) {
196 aoc_assert(++visits <= VISITS, "vault search exceeds visit cap");
197 if (f->x == 3 && f->y == 3) {
198 if (longest ? depth > best : depth < best) {
199 best = depth;
200 if (!longest) {
201 memcpy(shortest, path_, (size_t)depth);
202 }
203 }
204 depth--;
205 continue;
206 }
207 if (!longest && depth >= best) {
208 depth--;
209 continue;
210 }
211 uint32_t hash = digest(f->hash);
212 int nibble[4] = {(int)((hash >> 4) & 15), (int)(hash & 15),
213 (int)((hash >> 12) & 15), (int)((hash >> 8) & 15)};
214 f->doors = 0;
215 for (int k = 0; k < 4; k++) {
216 if (nibble[k] >= 11) {
217 f->doors |= (uint8_t)(1 << k);
218 }
219 }
220 }
221 int dir = f->next++;
222 if (dir == 4) {
223 depth--;
224 continue;
225 }
226 int x = f->x + dx[dir], y = f->y + dy[dir];
227 if (!(f->doors & (1 << dir)) || x < 0 || y < 0 || x > 3 || y > 3) {
228 continue;
229 }
230 aoc_assert(depth < DEPTH, "vault path exceeds depth cap");
231 struct frame *child = stack_ + depth + 1;
232 child->hash = f->hash;
233 feed(&child->hash, (uint8_t)directions[dir]);
234 child->x = (uint8_t)x;
235 child->y = (uint8_t)y;
236 child->next = 0;
237 path_[depth++] = directions[dir];
238 }
239 aoc_assert(best >= 0 && best <= DEPTH, "vault unreachable");
240 if (longest) {
241 return slice_from_i64(best);
242 }
243 return slice_from_text(shortest, (size_t)best);
244}
245
246slice part1(slice in) {
247 return solve(in, 0);
248}
249
250slice part2(slice in) {
251 return solve(in, 1);
252}
253
254static slice estimate(slice in) {
255 load(in);
256 return slice_from_i64(DEPTH);
257}
258
259const struct aoc_method aoc_methods[] = {
260 {"estimate", estimate},
261 {0, 0},
262};aoc.h
1#ifndef AOC_H
2#define AOC_H
3
4#include <stdarg.h>
5#include <stddef.h>
6#include <stdint.h>
7#include <stdlib.h>
8#include <string.h>
9
10/* The only required boundary between infra and a solution.
11 * `input` is read-only and is not owned by the solution.
12 * The returned slice is allocated with malloc. It is the only
13 * block still live when the function returns. Infra copies it
14 * and then frees it.
15 */
16typedef struct {
17 uint8_t *p;
18 size_t l;
19} slice;
20
21/* p is null and l is 0. Infra uses this when a run has no output. */
22static const slice empty_slice = {0};
23
24typedef slice (*aoc_fn)(slice);
25
26/* One named method. The name is a C identifier, at most 31
27 * characters, and it is the URL suffix: /YYYY/D/P/<name>.
28 * estimate and span are examples, not a fixed list. A day
29 * exports as many as it wants. The array ends with {0, 0}.
30 * part1 and part2 are not entries in this list.
31 */
32struct aoc_method {
33 const char *name;
34 aoc_fn fn;
35};
36
37slice part1(slice input);
38slice part2(slice input);
39
40extern const struct aoc_method aoc_methods[];
41
42/* Provided by the runtime. Records msg and returns. */
43void aoc_fail(const char *msg);
44
45/* Stops the run when cond is false and reports msg. */
46_Noreturn void aoc_assert_fail(const char *msg);
47#ifndef aoc_assert
48#define aoc_assert(cond, msg) \
49 do { \
50 if (!(cond)) { \
51 aoc_assert_fail(msg); \
52 } \
53 } while (0)
54#endif
55
56/* Decimal text of a uint64_t is at most 20 digits. A sign and a
57 * little spare fit here. Size a number buffer from this.
58 */
59enum { AOC_I64_TEXT = 32 };
60
61/* Decimal digits of v. No sign. d has room for 20 digits. */
62static inline char *aoc_u64_text(char *d, uint64_t v) {
63 char tmp[AOC_I64_TEXT];
64 char *end = tmp + AOC_I64_TEXT;
65 char *p = end;
66 size_t n;
67 do {
68 *--p = (char)('0' + (v % 10ull));
69 v /= 10ull;
70 } while (v);
71 n = (size_t)(end - p);
72 memcpy(d, p, n);
73 return d + n;
74}
75
76/* Decimal digits of v. The minimum int64_t is not negated. */
77static inline char *aoc_i64_text(char *d, int64_t v) {
78 uint64_t u;
79 if (v < 0) {
80 *d++ = '-';
81 u = (uint64_t)(-(v + 1)) + 1ull;
82 } else {
83 u = (uint64_t)v;
84 }
85 return aoc_u64_text(d, u);
86}
87
88/* n values, one space between them. The author knows the order. */
89static inline char *aoc_u64s(char *d, const uint64_t *v, size_t n) {
90 size_t i;
91 for (i = 0; i < n; i++) {
92 if (i) {
93 *d++ = ' ';
94 }
95 d = aoc_u64_text(d, v[i]);
96 }
97 return d;
98}
99
100static inline char *aoc_i64s(char *d, const int64_t *v, size_t n) {
101 size_t i;
102 for (i = 0; i < n; i++) {
103 if (i) {
104 *d++ = ' ';
105 }
106 d = aoc_i64_text(d, v[i]);
107 }
108 return d;
109}
110
111static inline char *aoc_ints(char *d, const int *v, size_t n) {
112 size_t i;
113 for (i = 0; i < n; i++) {
114 if (i) {
115 *d++ = ' ';
116 }
117 d = aoc_i64_text(d, (int64_t)v[i]);
118 }
119 return d;
120}
121
122/* Write fmt at buf. Return the cursor for the next call.
123 * %d takes int. %i takes int64_t. %u takes uint64_t.
124 * %s takes a C string. %% is a percent sign.
125 * A literal run is memcpy.
126 * %D takes (int *, size_t). %I takes (int64_t *, size_t).
127 * %U takes (uint64_t *, size_t). One space between values.
128 */
129static inline char *aoc_vprintf(const char *fmt, char *buf, va_list ap) {
130 while (*fmt) {
131 const char *lit = fmt;
132 size_t n;
133 while (*fmt && *fmt != '%') {
134 fmt++;
135 }
136 n = (size_t)(fmt - lit);
137 if (n) {
138 memcpy(buf, lit, n);
139 buf += n;
140 }
141 if (*fmt != '%') {
142 break;
143 }
144 fmt++;
145 if (*fmt == '%') {
146 *buf++ = '%';
147 fmt++;
148 continue;
149 }
150 if (*fmt == 's') {
151 const char *s = va_arg(ap, const char *);
152 n = strlen(s);
153 if (n) {
154 memcpy(buf, s, n);
155 buf += n;
156 }
157 fmt++;
158 continue;
159 }
160 if (*fmt == 'd') {
161 buf = aoc_i64_text(buf, (int64_t)va_arg(ap, int));
162 fmt++;
163 continue;
164 }
165 if (*fmt == 'i') {
166 buf = aoc_i64_text(buf, va_arg(ap, int64_t));
167 fmt++;
168 continue;
169 }
170 if (*fmt == 'u') {
171 buf = aoc_u64_text(buf, va_arg(ap, uint64_t));
172 fmt++;
173 continue;
174 }
175 if (*fmt == 'D') {
176 const int *v = va_arg(ap, int *);
177 buf = aoc_ints(buf, v, va_arg(ap, size_t));
178 fmt++;
179 continue;
180 }
181 if (*fmt == 'I') {
182 const int64_t *v = va_arg(ap, int64_t *);
183 buf = aoc_i64s(buf, v, va_arg(ap, size_t));
184 fmt++;
185 continue;
186 }
187 if (*fmt == 'U') {
188 const uint64_t *v = va_arg(ap, uint64_t *);
189 buf = aoc_u64s(buf, v, va_arg(ap, size_t));
190 fmt++;
191 continue;
192 }
193 aoc_assert(0, "bad format");
194 }
195 return buf;
196}
197
198static inline char *aoc_printf(const char *fmt, char *buf, ...) {
199 va_list ap;
200 va_start(ap, buf);
201 buf = aoc_vprintf(fmt, buf, ap);
202 va_end(ap);
203 return buf;
204}
205
206/* Copy n bytes of text into a malloc'd slice. */
207static inline slice slice_from_text(const char *s, size_t n) {
208 uint8_t *p = malloc(n);
209 aoc_assert(p, "out of memory");
210 if (n) {
211 memcpy(p, s, n);
212 }
213 return (slice){p, n};
214}
215
216/* Decimal text of v, allocated at AOC_I64_TEXT. The minimum
217 * int64_t is not negated. slice.l is the bytes written.
218 */
219static inline slice slice_from_i64(int64_t v) {
220 char tmp[AOC_I64_TEXT];
221 char *d;
222 uint8_t *p;
223 size_t n;
224 d = aoc_printf("%i", tmp, v);
225 n = (size_t)(d - tmp);
226 p = malloc(AOC_I64_TEXT);
227 aoc_assert(p, "out of memory");
228 memcpy(p, tmp, n);
229 return (slice){p, n};
230}
231
232/* Parse one decimal slice into *out. A leading '-' is allowed.
233 * Returns 1 on success, 0 for invalid text or int64_t overflow.
234 */
235static inline int slice_to_i64(slice s, int64_t *out) {
236 size_t i = 0;
237 int neg = 0;
238 uint64_t u = 0;
239 if (!s.p || s.l == 0 || !out) {
240 return 0;
241 }
242 if (s.p[0] == '-') {
243 neg = 1;
244 i = 1;
245 if (s.l == 1) {
246 return 0;
247 }
248 }
249 for (; i < s.l; i++) {
250 uint8_t c = s.p[i];
251 if (c < '0' || c > '9') {
252 return 0;
253 }
254 uint64_t digit = (uint64_t)(c - '0');
255 uint64_t limit = (uint64_t)INT64_MAX + (uint64_t)neg;
256 if (u > (limit - digit) / 10u) {
257 return 0;
258 }
259 u = u * 10u + digit;
260 }
261 if (neg) {
262 *out = u == (uint64_t)INT64_MAX + 1u ? INT64_MIN : -(int64_t)u;
263 } else {
264 *out = (int64_t)u;
265 }
266 return 1;
267}
268
269#endifThe aha moment
Sixteen rooms. After the elevator puzzle, this maze should be a holiday. Mark each visited coordinate and avoid going in circles. Then the example sends us down and back up—and the doors have changed. With passcode hijkl, the path DU returns to the start but hashes differently. Our familiar visited-room rule would throw away a useful move. Being in the same place no longer means facing the same problem.
The state must include the path taken so far. Two visits to the same coordinate can have different futures, so neither may be discarded just because the room was seen before. This turns the problem into a tree of path prefixes. Compute the hash for the current prefix, use its first four hexadecimal characters in U, D, L, R order, and generate only open doors that also stay inside the grid. A door indicated open by the hash still cannot lead through an outer wall.
For the shortest path, breadth-first search is the natural first choice: the first prefix reaching the vault has minimum length. The supplied implementation uses depth-first search instead, keeping the best complete path found so far. Once another prefix is already that long, extending it cannot improve the answer, so it can be pruned. Both approaches are exact; depth-first search keeps only one active branch and its saved state at each depth.
Now curiosity gets the better of us: how long can a successful route be? The example answers with hundreds of steps through sixteen rooms. That is a pointed reminder that “longest path” here allows revisits. Remove the pruning that discarded long prefixes. But stop each branch the instant it reaches the vault; walking out again would be exploring a different question.
Has losing the visited set made exhaustive search hopeless? Run a bounded experiment before deciding. For the local passcode, the entire tree contains 37,209 visited prefixes and 1,082 routes into the vault. The longest success takes 436 moves; a few doomed branches reach 442. That is a relief: this input is small enough to explore completely. The measurement supports a practical bound for it, without promising that every passcode has a small or finite tree.
Hashing the full passcode and path again at every room repeats work on common prefixes. Save an incremental MD5 context at each depth, copy the parent's context, and feed just the new direction. Compute the door digest from a copy so finalizing it does not damage the context needed by descendants. This improves the cost of exploring the same exact tree; it does not merge distinct histories.
The implementation accepts passcodes of at most 64 lowercase letters or digits, at most 200,000 room-prefix visits, and paths through depth 1,024. All exceed the measured local requirements. If an unexplored continuation would cross a bound, it rejects the search rather than reporting a merely longest-so-far path as the answer. The estimate method returns the fixed depth cap, which is a declared limit rather than a prediction of this passcode's search size.
See also
Categories for 2015–2024 adapted from u/Boojum’s 500 Stars: A Categorization and Mega-Guide ↗. A day can belong to several categories. Tags from 2025 onward are our additions.
Try your input
One POST, one reply. Your input is not saved.