@@ -0,0 +1,25 @@ | |||
import sys | |||
def op(a, trans=str.maketrans('01', '10')): | |||
return a + '0' + a[::-1].translate(trans) | |||
def checksum(string): | |||
return ''.join('01'[a == b] for a, b in zip(string[::2], string[1::2])) | |||
def expand(string, lim): | |||
while len(string) < lim: | |||
string = op(string) | |||
string = string[:lim] | |||
chk = checksum(string) | |||
while len(chk) % 2 == 0: | |||
chk = checksum(chk) | |||
return chk | |||
text = sys.stdin.read().strip() | |||
print(expand(text, 272)) | |||
print(expand(text, 35651584)) |
@@ -0,0 +1,24 @@ | |||
import sys | |||
import toolkit | |||
def advance(path, pos): | |||
digest = toolkit.md5(text + path) | |||
for d in [d for d, c in zip('UDLR', digest) if c in 'bcdef']: | |||
path1 = path + d | |||
new1 = pos + mapping[d] | |||
if 0 <= new1.real <= 3 and 0 <= new1.imag <= 3: | |||
yield path1, new1 | |||
text = sys.stdin.read().strip() | |||
mapping = {'U': -1j, 'D': 1j, 'L': -1, 'R': 1} | |||
edge = {('', 0)} | |||
valid = [] | |||
while edge: | |||
edge = {new for old in edge for new in advance(*old)} | |||
valid += [new for new in edge if new[1] == 3 + 3j] | |||
edge -= set(valid) | |||
print(valid[0][0]) | |||
print(len(valid[-1][0])) |
@@ -0,0 +1,15 @@ | |||
import sys | |||
def march(text): | |||
base = '.' + text + '.' | |||
for i in range(len(text)): | |||
yield '.^'[base[i:i + 3] in {'^^.', '.^^', '^..', '..^'}] | |||
text = sys.stdin.read().strip() | |||
seen = [text] | |||
for i in range(400_000): | |||
seen.append(''.join(march(seen[-1]))) | |||
print(''.join(seen[:40]).count('.')) | |||
print(''.join(seen[:400_000]).count('.')) |