소스 검색

2016/18

master
Roderic Day 4 년 전
부모
커밋
e7e2a7b66f
3개의 변경된 파일64개의 추가작업 그리고 0개의 파일을 삭제
  1. +25
    -0
      y2016/p16.py
  2. +24
    -0
      y2016/p17.py
  3. +15
    -0
      y2016/p18.py

+ 25
- 0
y2016/p16.py 파일 보기

@@ -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))

+ 24
- 0
y2016/p17.py 파일 보기

@@ -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]))

+ 15
- 0
y2016/p18.py 파일 보기

@@ -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('.'))

Loading…
취소
저장